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
43 lines
1.1 KiB
package test
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"github.com/tencentyun/cos-go-sdk-v5"
|
|
"net/http"
|
|
"net/url"
|
|
"os"
|
|
"path"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestAnnexUpload(t *testing.T) {
|
|
u, _ := url.Parse("https://hudongzhuanjia-1251209212.cos.ap-guangzhou.myqcloud.com")
|
|
b := &cos.BaseURL{BucketURL: u}
|
|
client := cos.NewClient(b, &http.Client{
|
|
Transport: &cos.AuthorizationTransport{
|
|
SecretID: "AKIDo2B9WqpvkSKQPPpplVAdv65QdpDfMRIz",
|
|
SecretKey: "fEcu35xdCbpU3azFLH2lU2f8UpAOQHZs",
|
|
},
|
|
})
|
|
gifFile, err := os.OpenFile("123.gif", os.O_RDONLY, os.ModePerm)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
picName := fmt.Sprintf("hdzj/upload/%d%s", time.Now().UnixNano(), path.Ext(gifFile.Name()))
|
|
_, err = client.Object.Put(context.Background(), picName, gifFile, nil)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
fmt.Println("上传成功,路径:", fmt.Sprintf("%s/%s", u.String(), picName))
|
|
objs := []cos.Object{{Key: picName}}
|
|
odmo := new(cos.ObjectDeleteMultiOptions)
|
|
odmo.Objects = objs
|
|
odmr, _, err := client.Object.DeleteMulti(context.Background(), odmo)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
fmt.Println(odmr)
|
|
}
|