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.

43 lines
842 B

  1. package main
  2. import (
  3. "context"
  4. "fmt"
  5. "net/url"
  6. "os"
  7. "net/http"
  8. "github.com/tencentyun/cos-go-sdk-v5"
  9. "github.com/tencentyun/cos-go-sdk-v5/debug"
  10. )
  11. func main() {
  12. u, _ := url.Parse("https://test-1253846586.cos.ap-guangzhou.myqcloud.com")
  13. b := &cos.BaseURL{
  14. BucketURL: u,
  15. }
  16. c := cos.NewClient(b, &http.Client{
  17. Transport: &cos.AuthorizationTransport{
  18. SecretID: os.Getenv("COS_SECRETID"),
  19. SecretKey: os.Getenv("COS_SECRETKEY"),
  20. Transport: &debug.DebugRequestTransport{
  21. RequestHeader: true,
  22. RequestBody: true,
  23. ResponseHeader: true,
  24. ResponseBody: true,
  25. },
  26. },
  27. })
  28. opt := &cos.ListMultipartUploadsOptions{
  29. Prefix: "t",
  30. }
  31. v, _, err := c.Bucket.ListMultipartUploads(context.Background(), opt)
  32. if err != nil {
  33. panic(err)
  34. }
  35. for _, p := range v.Uploads {
  36. fmt.Printf("%s\n", p.Key)
  37. }
  38. }