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.

42 lines
921 B

  1. package main
  2. import (
  3. "context"
  4. "net/url"
  5. "os"
  6. "time"
  7. "net/http"
  8. "fmt"
  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("http://tencentyun02-1252448703.cos.ap-guangzhou.myqcloud.com")
  14. b := &cos.BaseURL{BucketURL: u}
  15. c := cos.NewClient(b, &http.Client{
  16. //设置超时时间
  17. Timeout: 100 * time.Second,
  18. Transport: &cos.AuthorizationTransport{
  19. SecretID: os.Getenv("COS_Key"),
  20. SecretKey: os.Getenv("COS_Secret"),
  21. Transport: &debug.DebugRequestTransport{
  22. RequestHeader: false,
  23. RequestBody: false,
  24. ResponseHeader: false,
  25. ResponseBody: false,
  26. },
  27. },
  28. })
  29. f,err:=os.Open("E:/cos-php-sdk.zip")
  30. if err!=nil {panic(err)}
  31. opt := &cos.MultiUploadOptions{
  32. OptIni: nil,
  33. PartSize:1,
  34. }
  35. v, _, err := c.Object.MultiUpload(
  36. context.Background(), "test", f, opt,
  37. )
  38. if err!=nil {panic(err)}
  39. fmt.Println(v)
  40. }