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.

45 lines
888 B

  1. package main
  2. import (
  3. "context"
  4. "fmt"
  5. "net/url"
  6. "strings"
  7. "io/ioutil"
  8. "github.com/tencentyun/cos-go-sdk-v5"
  9. )
  10. func upload(c *cos.Client, name string) {
  11. f := strings.NewReader("test")
  12. f = strings.NewReader("test xxx")
  13. opt := &cos.ObjectPutOptions{
  14. ObjectPutHeaderOptions: &cos.ObjectPutHeaderOptions{
  15. ContentType: "text/html",
  16. },
  17. ACLHeaderOptions: &cos.ACLHeaderOptions{
  18. XCosACL: "public-read",
  19. },
  20. }
  21. c.Object.Put(context.Background(), name, f, opt)
  22. return
  23. }
  24. func main() {
  25. u, _ := url.Parse("https://test-1253846586.cos.ap-guangzhou.myqcloud.com")
  26. b := &cos.BaseURL{BucketURL: u}
  27. c := cos.NewClient(b, nil)
  28. name := "test/anonymous_get.go"
  29. upload(c, name)
  30. resp, err := c.Object.Get(context.Background(), name, nil)
  31. if err != nil {
  32. panic(err)
  33. return
  34. }
  35. bs, _ := ioutil.ReadAll(resp.Body)
  36. defer resp.Body.Close()
  37. fmt.Printf("%s\n", string(bs))
  38. }