You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
823 B

  1. package main
  2. import (
  3. "context"
  4. "fmt"
  5. "net/url"
  6. "os"
  7. "time"
  8. "net/http"
  9. "github.com/tencentyun/cos-go-sdk-v5"
  10. "github.com/tencentyun/cos-go-sdk-v5/debug"
  11. )
  12. func main() {
  13. u, _ := url.Parse("https://test-1253846586.cos.ap-guangzhou.myqcloud.com")
  14. b := &cos.BaseURL{BucketURL: u}
  15. c := cos.NewClient(b, &http.Client{
  16. Transport: &cos.AuthorizationTransport{
  17. SecretID: os.Getenv("COS_SECRETID"),
  18. SecretKey: os.Getenv("COS_SECRETKEY"),
  19. Transport: &debug.DebugRequestTransport{
  20. RequestHeader: true,
  21. RequestBody: true,
  22. ResponseHeader: true,
  23. ResponseBody: true,
  24. },
  25. },
  26. })
  27. name := "test_multipart" + time.Now().Format(time.RFC3339)
  28. v, _, err := c.Object.InitiateMultipartUpload(context.Background(), name, nil)
  29. if err != nil {
  30. panic(err)
  31. }
  32. fmt.Printf("%s\n", v.UploadID)
  33. }