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.

54 lines
1.1 KiB

  1. package main
  2. import (
  3. "context"
  4. "net/url"
  5. "os"
  6. "strings"
  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: true,
  21. ResponseHeader: true,
  22. ResponseBody: true,
  23. },
  24. },
  25. })
  26. name := "test/objectPut.go"
  27. f := strings.NewReader("test")
  28. _, err := c.Object.Put(context.Background(), name, f, nil)
  29. if err != nil {
  30. panic(err)
  31. }
  32. name = "test/put_option.go"
  33. f = strings.NewReader("test xxx")
  34. opt := &cos.ObjectPutOptions{
  35. ObjectPutHeaderOptions: &cos.ObjectPutHeaderOptions{
  36. ContentType: "text/html",
  37. },
  38. ACLHeaderOptions: &cos.ACLHeaderOptions{
  39. //XCosACL: "public-read",
  40. XCosACL: "private",
  41. },
  42. }
  43. _, err = c.Object.Put(context.Background(), name, f, opt)
  44. if err != nil {
  45. panic(err)
  46. }
  47. }