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
937 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{BucketURL: u}
  14. c := cos.NewClient(b, &http.Client{
  15. Transport: &cos.AuthorizationTransport{
  16. SecretID: os.Getenv("COS_SECRETID"),
  17. SecretKey: os.Getenv("COS_SECRETKEY"),
  18. Transport: &debug.DebugRequestTransport{
  19. RequestHeader: true,
  20. RequestBody: false,
  21. ResponseHeader: true,
  22. ResponseBody: true,
  23. },
  24. },
  25. })
  26. name := "test_multipart.txt"
  27. v, _, err := c.Object.InitiateMultipartUpload(context.Background(), name, nil)
  28. if err != nil {
  29. panic(err)
  30. }
  31. fmt.Printf("%s\n", v.UploadID)
  32. resp, err := c.Object.AbortMultipartUpload(context.Background(), name, v.UploadID)
  33. if err != nil {
  34. panic(err)
  35. }
  36. fmt.Printf("%s\n", resp.Status)
  37. }