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.

40 lines
812 B

  1. package main
  2. import (
  3. "context"
  4. "net/http"
  5. "net/url"
  6. "os"
  7. "time"
  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("https://test-1259654469.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_SECRETID"),
  20. SecretKey: os.Getenv("COS_SECRETKEY"),
  21. Transport: &debug.DebugRequestTransport{
  22. RequestHeader: false,
  23. RequestBody: false,
  24. ResponseHeader: false,
  25. ResponseBody: false,
  26. },
  27. },
  28. })
  29. v, _, err := c.Object.Upload(
  30. context.Background(), "gomulput1G", "./test1G", nil,
  31. )
  32. if err != nil {
  33. panic(err)
  34. }
  35. fmt.Println(v)
  36. }