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.

53 lines
1.1 KiB

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