互动
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.

43 lines
1.1 KiB

5 years ago
5 years ago
5 years ago
  1. package test
  2. import (
  3. "context"
  4. "fmt"
  5. "github.com/tencentyun/cos-go-sdk-v5"
  6. "net/http"
  7. "net/url"
  8. "os"
  9. "path"
  10. "testing"
  11. "time"
  12. )
  13. func TestAnnexUpload(t *testing.T) {
  14. u, _ := url.Parse("https://hudongzhuanjia-1251209212.cos.ap-guangzhou.myqcloud.com")
  15. b := &cos.BaseURL{BucketURL: u}
  16. client := cos.NewClient(b, &http.Client{
  17. Transport: &cos.AuthorizationTransport{
  18. SecretID: "AKIDo2B9WqpvkSKQPPpplVAdv65QdpDfMRIz",
  19. SecretKey: "fEcu35xdCbpU3azFLH2lU2f8UpAOQHZs",
  20. },
  21. })
  22. gifFile, err := os.OpenFile("123.gif", os.O_RDONLY, os.ModePerm)
  23. if err != nil {
  24. t.Fatal(err)
  25. }
  26. picName := fmt.Sprintf("hdzj/upload/%d%s", time.Now().UnixNano(), path.Ext(gifFile.Name()))
  27. _, err = client.Object.Put(context.Background(), picName, gifFile, nil)
  28. if err != nil {
  29. t.Fatal(err)
  30. }
  31. fmt.Println("上传成功,路径:", fmt.Sprintf("%s/%s", u.String(), picName))
  32. objs := []cos.Object{{Key: picName}}
  33. odmo := new(cos.ObjectDeleteMultiOptions)
  34. odmo.Objects = objs
  35. odmr, _, err := client.Object.DeleteMulti(context.Background(), odmo)
  36. if err != nil {
  37. t.Fatal(err)
  38. }
  39. fmt.Println(odmr)
  40. }