1package main 2 3import ( 4 "context" 5 "fmt" 6 "os" 7 8 "net/url" 9 "strings" 10 11 "net/http" 12 13 "github.com/mozillazg/go-cos" 14 "github.com/mozillazg/go-cos/debug" 15) 16 17func initUpload(c *cos.Client, name string) *cos.InitiateMultipartUploadResult { 18 v, _, err := c.Object.InitiateMultipartUpload(context.Background(), name, nil) 19 if err != nil { 20 panic(err) 21 } 22 fmt.Printf("%#v\n", v) 23 return v 24} 25 26func main() { 27 u, _ := url.Parse(os.Getenv("COS_BUCKET_URL")) 28 b := &cos.BaseURL{BucketURL: u} 29 c := cos.NewClient(b, &http.Client{ 30 Transport: &cos.AuthorizationTransport{ 31 SecretID: os.Getenv("COS_SECRETID"), 32 SecretKey: os.Getenv("COS_SECRETKEY"), 33 Transport: &debug.DebugRequestTransport{ 34 RequestHeader: true, 35 RequestBody: true, 36 ResponseHeader: true, 37 ResponseBody: true, 38 }, 39 }, 40 }) 41 42 name := "test/test_multi_upload.go" 43 up := initUpload(c, name) 44 uploadID := up.UploadID 45 46 f := strings.NewReader("test heoo") 47 _, err := c.Object.UploadPart( 48 context.Background(), name, uploadID, 1, f, nil, 49 ) 50 if err != nil { 51 panic(err) 52 } 53} 54