package sample import ( "fmt" "io/ioutil" "strings" "github.com/aliyun/aliyun-oss-go-sdk/oss" ) // SignURLSample sign url sample func SignURLSample() { // 创建Bucket bucket, err := GetTestBucket(bucketName) if err != nil { HandleError(err) } // put object signedURL, err := bucket.SignURL(objectKey, oss.HTTPPut, 60) if err != nil { HandleError(err) } var val = "花间一壶酒,独酌无相亲。 举杯邀明月,对影成三人。" err = bucket.PutObjectWithURL(signedURL, strings.NewReader(val)) if err != nil { HandleError(err) } // put object with option options := []oss.Option{ oss.Meta("myprop", "mypropval"), oss.ContentType("image/tiff"), } signedURL, err = bucket.SignURL(objectKey, oss.HTTPPut, 60, options...) if err != nil { HandleError(err) } err = bucket.PutObjectFromFileWithURL(signedURL, localFile, options...) if err != nil { HandleError(err) } // get object signedURL, err = bucket.SignURL(objectKey, oss.HTTPGet, 60) if err != nil { HandleError(err) } body, err := bucket.GetObjectWithURL(signedURL) if err != nil { HandleError(err) } // read content data, err := ioutil.ReadAll(body) body.Close() data = data // use data err = bucket.GetObjectToFileWithURL(signedURL, "mynewfile-1.jpg") if err != nil { HandleError(err) } // 删除object和bucket err = DeleteTestBucketAndObject(bucketName) if err != nil { HandleError(err) } fmt.Println("SignURLSample completed") }