Browse Source

add GetBucketObjectVersions & update tips when failed

tags/v0.7.6^2
jojoliang 5 years ago
parent
commit
517ae20fdc
  1. 58
      bucket.go
  2. 105
      bucket_test.go
  3. 9
      costesting/ci_test.go
  4. 38
      example/bucket/getLogging.go
  5. 64
      example/bucket/getObjectVersion.go
  6. 23
      example/object/MultiUpload.go
  7. 27
      example/object/abortMultipartUpload.go
  8. 12
      example/object/ci_put.go
  9. 35
      example/object/completeMultipartUpload.go
  10. 36
      example/object/copy.go
  11. 31
      example/object/copyPart.go
  12. 24
      example/object/delete.go
  13. 27
      example/object/deleteMultiple.go
  14. 42
      example/object/get.go
  15. 25
      example/object/getACL.go
  16. 24
      example/object/getAnonymous.go
  17. 32
      example/object/getByPresignedURL.go
  18. 24
      example/object/head.go
  19. 23
      example/object/initiateMultipartUpload.go
  20. 31
      example/object/listParts.go
  21. 26
      example/object/options.go
  22. 44
      example/object/presigned_url_with_token.go
  23. 35
      example/object/put.go
  24. 28
      example/object/putACL.go
  25. 24
      example/object/restore.go
  26. 81
      example/object/sse_c.go
  27. 75
      example/object/sse_cos.go
  28. 23
      example/object/upload.go
  29. 29
      example/object/uploadFile.go
  30. 27
      example/object/uploadPart.go

58
bucket.go

@ -102,3 +102,61 @@ type Bucket struct {
Region string `xml:"Location,omitempty"`
CreationDate string `xml:",omitempty"`
}
type BucketGetObjectVersionsOptions struct {
Prefix string `url:"prefix,omitempty"`
Delimiter string `url:"delimiter,omitempty"`
EncodingType string `url:"encoding-type,omitempty"`
KeyMarker string `url:"key-marker,omitempty"`
VersionIdMarker string `url:"version-id-marker,omitempty"`
MaxKeys int `url:"max-keys,omitempty"`
}
type BucketGetObjectVersionsResult struct {
XMLName xml.Name `xml:"ListVersionsResult"`
Name string `xml:"Name,omitempty"`
EncodingType string `xml:"EncodingType,omitempty"`
Prefix string `xml:"Prefix,omitempty"`
KeyMarker string `xml:"KeyMarker,omitempty"`
VersionIdMarker string `xml:"VersionIdMarker,omitempty"`
MaxKeys int `xml:"MaxKeys,omitempty"`
Delimiter string `xml:"Delimiter,omitempty"`
IsTruncated bool `xml:"IsTruncated,omitempty"`
NextKeyMarker string `xml:"NextKeyMarker,omitempty"`
NextVersionIdMarker string `xml:"NextVersionIdMarker,omitempty"`
CommonPrefixes []string `xml:"CommonPrefixes>Prefix,omitempty"`
Version []ListVersionsResultVersion `xml:"Version,omitempty"`
DeleteMarker []ListVersionsResultDeleteMarker `xml:"DeleteMarker,omitempty"`
}
type ListVersionsResultVersion struct {
Key string `xml:"Key,omitempty"`
VersionId string `xml:"VersionId,omitempty"`
IsLatest bool `xml:"IsLatest,omitempty"`
LastModified string `xml:"LastModified,omitempty"`
ETag string `xml:"ETag,omitempty"`
Size int `xml:"Size,omitempty"`
StorageClass string `xml:"StorageClass,omitempty"`
Owner *Owner `xml:"Owner,omitempty"`
}
type ListVersionsResultDeleteMarker struct {
Key string `xml:"Key,omitempty"`
VersionId string `xml:"VersionId,omitempty"`
IsLatest bool `xml:"IsLatest,omitempty"`
LastModified string `xml:"LastModified,omitempty"`
Owner *Owner `xml:"Owner,omitempty"`
}
func (s *BucketService) GetObjectVersions(ctx context.Context, opt *BucketGetObjectVersionsOptions) (*BucketGetObjectVersionsResult, *Response, error) {
var res BucketGetObjectVersionsResult
sendOpt := sendOptions{
baseURL: s.client.BaseURL.BucketURL,
uri: "/?versions",
method: http.MethodGet,
optQuery: opt,
result: &res,
}
resp, err := s.client.send(ctx, &sendOpt)
return &res, resp, err
}

105
bucket_test.go

@ -150,3 +150,108 @@ func TestBucketService_Head(t *testing.T) {
t.Fatalf("Bucket.Head returned error: %v", err)
}
}
func TestBucketService_GetObjectVersions(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodGet)
w.WriteHeader(http.StatusOK)
vs := values{
"versions": "",
"delimiter": "/",
}
testFormValues(t, r, vs)
fmt.Fprint(w, `<?xml version='1.0' encoding='utf-8' ?>
<ListVersionsResult>
<Name>examplebucket-1250000000</Name>
<Prefix/>
<KeyMarker/>
<VersionIdMarker/>
<MaxKeys>1000</MaxKeys>
<IsTruncated>false</IsTruncated>
<Delimiter>/</Delimiter>
<CommonPrefixes>
<Prefix>example-folder-1/</Prefix>
</CommonPrefixes>
<CommonPrefixes>
<Prefix>example-folder-2/</Prefix>
</CommonPrefixes>
<Version>
<Key>example-object-1.jpg</Key>
<VersionId>MTg0NDUxNzgxMjEzNTU3NTk1Mjg</VersionId>
<IsLatest>true</IsLatest>
<LastModified>2019-08-16T10:45:53.000Z</LastModified>
<ETag>&quot;5d1143df07a17b23320d0da161e2819e&quot;</ETag>
<Size>30</Size>
<StorageClass>STANDARD</StorageClass>
<Owner>
<ID>1250000000</ID>
<DisplayName>1250000000</DisplayName>
</Owner>
</Version>
<DeleteMarker>
<Key>example-object-1.jpg</Key>
<VersionId>MTg0NDUxNzgxMjEzNjE1OTcxMzM</VersionId>
<IsLatest>false</IsLatest>
<LastModified>2019-08-16T10:45:47.000Z</LastModified>
<Owner>
<ID>1250000000</ID>
<DisplayName>1250000000</DisplayName>
</Owner>
</DeleteMarker>
</ListVersionsResult>`)
})
want := &BucketGetObjectVersionsResult {
XMLName: xml.Name { Local: "ListVersionsResult" },
Name: "examplebucket-1250000000",
MaxKeys: 1000,
IsTruncated: false,
Delimiter: "/",
CommonPrefixes: []string {
"example-folder-1/",
"example-folder-2/",
},
Version: []ListVersionsResultVersion {
{
Key: "example-object-1.jpg",
VersionId: "MTg0NDUxNzgxMjEzNTU3NTk1Mjg",
IsLatest: true,
LastModified: "2019-08-16T10:45:53.000Z",
ETag: "\"5d1143df07a17b23320d0da161e2819e\"",
Size: 30,
StorageClass: "STANDARD",
Owner: &Owner {
ID: "1250000000",
DisplayName: "1250000000",
},
},
},
DeleteMarker: []ListVersionsResultDeleteMarker {
{
Key: "example-object-1.jpg",
VersionId: "MTg0NDUxNzgxMjEzNjE1OTcxMzM",
IsLatest: false,
LastModified: "2019-08-16T10:45:47.000Z",
Owner: &Owner {
ID: "1250000000",
DisplayName: "1250000000",
},
},
},
}
opt := &BucketGetObjectVersionsOptions {
Delimiter: "/",
}
res, _, err := client.Bucket.GetObjectVersions(context.Background(), opt)
if err != nil {
t.Fatalf("Bucket.GetObjectVersions returned error: %v", err)
}
if !reflect.DeepEqual(res, want) {
t.Errorf("Bucket.GetObjectVersions returned\n%+v\nwant\n%+v", res, want)
}
}

9
costesting/ci_test.go

@ -184,6 +184,15 @@ func (s *CosTestSuite) TestGetBucket() {
assert.Nil(s.T(), err, "GetBucket Failed")
}
func (s *CosTestSuite) TestGetObjectVersions() {
opt := &cos.BucketGetObjectVersionsOptions {
Prefix: "中文",
MaxKeys: 3,
}
_, _, err := s.Client.Bucket.GetObjectVersions(context.Background(), opt)
assert.Nil(s.T(), err, "GetObjectVersions Failed")
}
func (s *CosTestSuite) TestGetBucketLocation() {
v, _, err := s.Client.Bucket.GetLocation(context.Background())
assert.Nil(s.T(), err, "GetLocation Failed")

38
example/bucket/getLogging.go

@ -0,0 +1,38 @@
package main
import (
"context"
"fmt"
"net/url"
"os"
"net/http"
"github.com/tencentyun/cos-go-sdk-v5"
"github.com/tencentyun/cos-go-sdk-v5/debug"
)
func main() {
u, _ := url.Parse("https://bj-1259654469.cos.ap-beijing.myqcloud.com")
b := &cos.BaseURL{
BucketURL: u,
}
c := cos.NewClient(b, &http.Client{
Transport: &cos.AuthorizationTransport{
SecretID: os.Getenv("COS_SECRETID"),
SecretKey: os.Getenv("COS_SECRETKEY"),
Transport: &debug.DebugRequestTransport{
RequestHeader: true,
RequestBody: true,
ResponseHeader: true,
ResponseBody: true,
},
},
})
v, _, err := c.Bucket.GetLogging(context.Background())
if err != nil {
panic(err)
}
fmt.Printf("%+v\n", v.LoggingEnabled)
}

64
example/bucket/getObjectVersion.go

@ -0,0 +1,64 @@
package main
import (
"context"
"fmt"
"os"
"net/url"
"net/http"
"github.com/tencentyun/cos-go-sdk-v5"
"github.com/tencentyun/cos-go-sdk-v5/debug"
)
func log_status(err error) {
if err == nil {
return
}
if cos.IsNotFoundError(err) {
// WARN
fmt.Println("WARN: Resource is not existed")
} else if e, ok := cos.IsCOSError(err); ok {
fmt.Printf("ERROR: Code: %v\n", e.Code)
fmt.Printf("ERROR: Message: %v\n", e.Message)
fmt.Printf("ERROR: Resource: %v\n", e.Resource)
fmt.Printf("ERROR: RequestId: %v\n", e.RequestID)
// ERROR
} else {
fmt.Printf("ERROR: %v\n", err)
// ERROR
}
}
func main() {
u, _ := url.Parse("https://test-1259654469.cos.ap-guangzhou.myqcloud.com")
b := &cos.BaseURL{
BucketURL: u,
}
c := cos.NewClient(b, &http.Client{
Transport: &cos.AuthorizationTransport{
SecretID: os.Getenv("COS_SECRETID"),
SecretKey: os.Getenv("COS_SECRETKEY"),
Transport: &debug.DebugRequestTransport{
RequestHeader: true,
RequestBody: true,
ResponseHeader: true,
ResponseBody: true,
},
},
})
opt := &cos.BucketGetObjectVersionsOptions {
Delimiter: "/",
MaxKeys: 1,
}
v, _, err := c.Bucket.GetObjectVersions(context.Background(), opt)
log_status(err)
for _, c := range v.Version {
fmt.Printf("%v, %v, %v\n", c.Key, c.Size, c.IsLatest)
}
}

23
example/object/MutiUpload.go → example/object/MultiUpload.go

@ -12,6 +12,25 @@ import (
"github.com/tencentyun/cos-go-sdk-v5/debug"
)
func log_status(err error) {
if err == nil {
return
}
if cos.IsNotFoundError(err) {
// WARN
fmt.Println("WARN: Resource is not existed")
} else if e, ok := cos.IsCOSError(err); ok {
fmt.Printf("ERROR: Code: %v\n", e.Code)
fmt.Printf("ERROR: Message: %v\n", e.Message)
fmt.Printf("ERROR: Resource: %v\n", e.Resource)
fmt.Printf("ERROR: RequestId: %v\n", e.RequestID)
// ERROR
} else {
fmt.Printf("ERROR: %v\n", err)
// ERROR
}
}
func main() {
u, _ := url.Parse("http://alanbj-1251668577.cos.ap-beijing.myqcloud.com")
b := &cos.BaseURL{BucketURL: u}
@ -37,8 +56,6 @@ func main() {
v, _, err := c.Object.MultiUpload(
context.Background(), "test/gomulput1G", "./test1G", opt,
)
if err != nil {
panic(err)
}
log_status(err)
fmt.Println(v)
}

27
example/object/abortMultipartUpload.go

@ -12,6 +12,25 @@ import (
"github.com/tencentyun/cos-go-sdk-v5/debug"
)
func log_status(err error) {
if err == nil {
return
}
if cos.IsNotFoundError(err) {
// WARN
fmt.Println("WARN: Resource is not existed")
} else if e, ok := cos.IsCOSError(err); ok {
fmt.Printf("ERROR: Code: %v\n", e.Code)
fmt.Printf("ERROR: Message: %v\n", e.Message)
fmt.Printf("ERROR: Resource: %v\n", e.Resource)
fmt.Printf("ERROR: RequestId: %v\n", e.RequestID)
// ERROR
} else {
fmt.Printf("ERROR: %v\n", err)
// ERROR
}
}
func main() {
u, _ := url.Parse("https://test-1253846586.cos.ap-guangzhou.myqcloud.com")
b := &cos.BaseURL{BucketURL: u}
@ -30,14 +49,10 @@ func main() {
name := "test_multipart.txt"
v, _, err := c.Object.InitiateMultipartUpload(context.Background(), name, nil)
if err != nil {
panic(err)
}
log_status(err)
fmt.Printf("%s\n", v.UploadID)
resp, err := c.Object.AbortMultipartUpload(context.Background(), name, v.UploadID)
if err != nil {
panic(err)
}
log_status(err)
fmt.Printf("%s\n", resp.Status)
}

12
example/object/ci_put.go

@ -17,15 +17,15 @@ func log_status(err error) {
}
if cos.IsNotFoundError(err) {
// WARN
fmt.Println("Resource is not existed")
fmt.Println("WARN: Resource is not existed")
} else if e, ok := cos.IsCOSError(err); ok {
fmt.Printf("Code: %v\n", e.Code)
fmt.Printf("Message: %v\n", e.Message)
fmt.Printf("Resource: %v\n", e.Resource)
fmt.Printf("RequestId: %v\n", e.RequestID)
fmt.Printf("ERROR: Code: %v\n", e.Code)
fmt.Printf("ERROR: Message: %v\n", e.Message)
fmt.Printf("ERROR: Resource: %v\n", e.Resource)
fmt.Printf("ERROR: RequestId: %v\n", e.RequestID)
// ERROR
} else {
fmt.Println(err)
fmt.Printf("ERROR: %v\n", err)
// ERROR
}
}

35
example/object/completeMultipartUpload.go

@ -14,11 +14,28 @@ import (
"github.com/tencentyun/cos-go-sdk-v5/debug"
)
func log_status(err error) {
if err == nil {
return
}
if cos.IsNotFoundError(err) {
// WARN
fmt.Println("WARN: Resource is not existed")
} else if e, ok := cos.IsCOSError(err); ok {
fmt.Printf("ERROR: Code: %v\n", e.Code)
fmt.Printf("ERROR: Message: %v\n", e.Message)
fmt.Printf("ERROR: Resource: %v\n", e.Resource)
fmt.Printf("ERROR: RequestId: %v\n", e.RequestID)
// ERROR
} else {
fmt.Printf("ERROR: %v\n", err)
// ERROR
}
}
func initUpload(c *cos.Client, name string) *cos.InitiateMultipartUploadResult {
v, _, err := c.Object.InitiateMultipartUpload(context.Background(), name, nil)
if err != nil {
panic(err)
}
log_status(err)
fmt.Printf("%#v\n", v)
return v
}
@ -27,7 +44,7 @@ func uploadPart(c *cos.Client, name string, uploadID string, blockSize, n int) s
b := make([]byte, blockSize)
if _, err := rand.Read(b); err != nil {
panic(err)
log_status(err)
}
s := fmt.Sprintf("%X", b)
f := strings.NewReader(s)
@ -35,15 +52,13 @@ func uploadPart(c *cos.Client, name string, uploadID string, blockSize, n int) s
resp, err := c.Object.UploadPart(
context.Background(), name, uploadID, n, f, nil,
)
if err != nil {
panic(err)
}
log_status(err)
fmt.Printf("%s\n", resp.Status)
return resp.Header.Get("Etag")
}
func main() {
u, _ := url.Parse("https://test-1253846586.cos.ap-guangzhou.myqcloud.com")
u, _ := url.Parse("https://test-1259654469.cos.ap-guangzhou.myqcloud.com")
b := &cos.BaseURL{BucketURL: u}
c := cos.NewClient(b, &http.Client{
Transport: &cos.AuthorizationTransport{
@ -86,9 +101,7 @@ func main() {
v, resp, err := c.Object.CompleteMultipartUpload(
context.Background(), name, uploadID, opt,
)
if err != nil {
panic(err)
}
log_status(err)
fmt.Printf("%s\n", resp.Status)
fmt.Printf("%#v\n", v)
fmt.Printf("%s\n", v.Location)

36
example/object/copy.go

@ -16,8 +16,27 @@ import (
"github.com/tencentyun/cos-go-sdk-v5/debug"
)
func log_status(err error) {
if err == nil {
return
}
if cos.IsNotFoundError(err) {
// WARN
fmt.Println("WARN: Resource is not existed")
} else if e, ok := cos.IsCOSError(err); ok {
fmt.Printf("ERROR: Code: %v\n", e.Code)
fmt.Printf("ERROR: Message: %v\n", e.Message)
fmt.Printf("ERROR: Resource: %v\n", e.Resource)
fmt.Printf("ERROR: RequestId: %v\n", e.RequestID)
// ERROR
} else {
fmt.Printf("ERROR: %v\n", err)
// ERROR
}
}
func main() {
u, _ := url.Parse("https://test-1253846586.cos.ap-guangzhou.myqcloud.com")
u, _ := url.Parse("https://test-1259654469.cos.ap-guangzhou.myqcloud.com")
b := &cos.BaseURL{BucketURL: u}
c := cos.NewClient(b, &http.Client{
Transport: &cos.AuthorizationTransport{
@ -37,24 +56,19 @@ func main() {
f := strings.NewReader(expected)
_, err := c.Object.Put(context.Background(), source, f, nil)
if err != nil {
panic(err)
}
log_status(err)
soruceURL := fmt.Sprintf("%s/%s", u.Host, source)
dest := fmt.Sprintf("test/objectMove_%d.go", time.Now().Nanosecond())
//opt := &cos.ObjectCopyOptions{}
res, _, err := c.Object.Copy(context.Background(), dest, soruceURL, nil)
if err != nil {
panic(err)
}
log_status(err)
fmt.Printf("%+v\n\n", res)
resp, err := c.Object.Get(context.Background(), dest, nil)
if err != nil {
panic(err)
}
bs, _ := ioutil.ReadAll(resp.Body)
log_status(err)
bs, _ := ioutil.ReadAll(resp.Body)
resp.Body.Close()
result := string(bs)
if result != expected {

31
example/object/copyPart.go

@ -13,11 +13,28 @@ import (
"github.com/tencentyun/cos-go-sdk-v5/debug"
)
func log_status(err error) {
if err == nil {
return
}
if cos.IsNotFoundError(err) {
// WARN
fmt.Println("WARN: Resource is not existed")
} else if e, ok := cos.IsCOSError(err); ok {
fmt.Printf("ERROR: Code: %v\n", e.Code)
fmt.Printf("ERROR: Message: %v\n", e.Message)
fmt.Printf("ERROR: Resource: %v\n", e.Resource)
fmt.Printf("ERROR: RequestId: %v\n", e.RequestID)
// ERROR
} else {
fmt.Printf("ERROR: %v\n", err)
// ERROR
}
}
func initUpload(c *cos.Client, name string) *cos.InitiateMultipartUploadResult {
v, _, err := c.Object.InitiateMultipartUpload(context.Background(), name, nil)
if err != nil {
panic(err)
}
log_status(err)
fmt.Printf("%#v\n", v)
return v
}
@ -46,9 +63,7 @@ func main() {
opt := &cos.ObjectCopyPartOptions{}
res, _, err := c.Object.CopyPart(
context.Background(), name, uploadID, 1, sourceUrl, opt)
if err != nil {
panic(err)
}
log_status(err)
fmt.Println("ETag:", res.ETag)
completeOpt := &cos.CompleteMultipartUploadOptions{}
@ -59,9 +74,7 @@ func main() {
v, resp, err := c.Object.CompleteMultipartUpload(
context.Background(), name, uploadID, completeOpt,
)
if err != nil {
panic(err)
}
log_status(err)
fmt.Printf("%s\n", resp.Status)
fmt.Printf("%#v\n", v)
fmt.Printf("%s\n", v.Location)

24
example/object/delete.go

@ -2,6 +2,7 @@ package main
import (
"context"
"fmt"
"net/url"
"os"
@ -11,6 +12,25 @@ import (
"github.com/tencentyun/cos-go-sdk-v5/debug"
)
func log_status(err error) {
if err == nil {
return
}
if cos.IsNotFoundError(err) {
// WARN
fmt.Println("WARN: Resource is not existed")
} else if e, ok := cos.IsCOSError(err); ok {
fmt.Printf("ERROR: Code: %v\n", e.Code)
fmt.Printf("ERROR: Message: %v\n", e.Message)
fmt.Printf("ERROR: Resource: %v\n", e.Resource)
fmt.Printf("ERROR: RequestId: %v\n", e.RequestID)
// ERROR
} else {
fmt.Printf("ERROR: %v\n", err)
// ERROR
}
}
func main() {
u, _ := url.Parse("https://test-1253846586.cos.ap-guangzhou.myqcloud.com")
b := &cos.BaseURL{BucketURL: u}
@ -30,7 +50,5 @@ func main() {
name := "test/objectPut.go"
_, err := c.Object.Delete(context.Background(), name, nil)
if err != nil {
panic(err)
}
log_status(err)
}

27
example/object/deleteMultiple.go

@ -18,10 +18,29 @@ import (
"github.com/tencentyun/cos-go-sdk-v5/debug"
)
func log_status(err error) {
if err == nil {
return
}
if cos.IsNotFoundError(err) {
// WARN
fmt.Println("WARN: Resource is not existed")
} else if e, ok := cos.IsCOSError(err); ok {
fmt.Printf("ERROR: Code: %v\n", e.Code)
fmt.Printf("ERROR: Message: %v\n", e.Message)
fmt.Printf("ERROR: Resource: %v\n", e.Resource)
fmt.Printf("ERROR: RequestId: %v\n", e.RequestID)
// ERROR
} else {
fmt.Printf("ERROR: %v\n", err)
// ERROR
}
}
func genBigData(blockSize int) []byte {
b := make([]byte, blockSize)
if _, err := rand.Read(b); err != nil {
panic(err)
log_status(err)
}
return b
}
@ -46,7 +65,7 @@ func uploadMulti(c *cos.Client) []string {
}
func main() {
u, _ := url.Parse("https://test-1253846586.cos.ap-guangzhou.myqcloud.com")
u, _ := url.Parse("https://test-1259654469.cos.ap-guangzhou.myqcloud.com")
b := &cos.BaseURL{BucketURL: u}
c := cos.NewClient(b, &http.Client{
Transport: &cos.AuthorizationTransport{
@ -89,9 +108,7 @@ func main() {
})
v, _, err := c.Object.DeleteMulti(ctx, opt)
if err != nil {
panic(err)
}
log_status(err)
for _, x := range v.DeletedObjects {
fmt.Printf("deleted %s\n", x.Key)

42
example/object/get.go

@ -13,6 +13,25 @@ import (
"github.com/tencentyun/cos-go-sdk-v5/debug"
)
func log_status(err error) {
if err == nil {
return
}
if cos.IsNotFoundError(err) {
// WARN
fmt.Println("WARN: Resource is not existed")
} else if e, ok := cos.IsCOSError(err); ok {
fmt.Printf("ERROR: Code: %v\n", e.Code)
fmt.Printf("ERROR: Message: %v\n", e.Message)
fmt.Printf("ERROR: Resource: %v\n", e.Resource)
fmt.Printf("ERROR: RequestId: %v\n", e.RequestID)
// ERROR
} else {
fmt.Printf("ERROR: %v\n", err)
// ERROR
}
}
func main() {
u, _ := url.Parse("https://test-1253846586.cos.ap-guangzhou.myqcloud.com")
b := &cos.BaseURL{BucketURL: u}
@ -32,31 +51,26 @@ func main() {
// Case1 Download object into ReadCloser(). the body needs to be closed
name := "test/hello.txt"
resp, err := c.Object.Get(context.Background(), name, nil)
if err != nil {
panic(err)
}
log_status(err)
bs, _ := ioutil.ReadAll(resp.Body)
resp.Body.Close()
fmt.Printf("%s\n", string(bs))
// Case2 Download object to local file. the body needs to be closed
fd, err := os.OpenFile("hello.txt", os.O_WRONLY|os.O_CREATE, 0660)
if err != nil {
panic(err)
}
log_status(err)
defer fd.Close()
resp, err = c.Object.Get(context.Background(), name, nil)
if err != nil {
panic(err)
}
log_status(err)
io.Copy(fd, resp.Body)
resp.Body.Close()
// Case3 Download object to local file path
_, err = c.Object.GetToFile(context.Background(), name, "hello_1.txt", nil)
if err != nil {
panic(err)
}
log_status(err)
// Case4 Download object with range header, can used to concurrent download
opt := &cos.ObjectGetOptions{
@ -64,9 +78,7 @@ func main() {
Range: "bytes=0-3",
}
resp, err = c.Object.Get(context.Background(), name, opt)
if err != nil {
panic(err)
}
log_status(err)
bs, _ = ioutil.ReadAll(resp.Body)
resp.Body.Close()
fmt.Printf("%s\n", string(bs))

25
example/object/getACL.go

@ -12,8 +12,27 @@ import (
"github.com/tencentyun/cos-go-sdk-v5/debug"
)
func log_status(err error) {
if err == nil {
return
}
if cos.IsNotFoundError(err) {
// WARN
fmt.Println("WARN: Resource is not existed")
} else if e, ok := cos.IsCOSError(err); ok {
fmt.Printf("ERROR: Code: %v\n", e.Code)
fmt.Printf("ERROR: Message: %v\n", e.Message)
fmt.Printf("ERROR: Resource: %v\n", e.Resource)
fmt.Printf("ERROR: RequestId: %v\n", e.RequestID)
// ERROR
} else {
fmt.Printf("ERROR: %v\n", err)
// ERROR
}
}
func main() {
u, _ := url.Parse("https://test-1253846586.cos.ap-guangzhou.myqcloud.com")
u, _ := url.Parse("https://test-1259654469.cos.ap-guangzhou.myqcloud.com")
b := &cos.BaseURL{BucketURL: u}
c := cos.NewClient(b, &http.Client{
Transport: &cos.AuthorizationTransport{
@ -30,9 +49,7 @@ func main() {
name := "test/hello.txt"
v, _, err := c.Object.GetACL(context.Background(), name)
if err != nil {
panic(err)
}
log_status(err)
for _, a := range v.AccessControlList {
fmt.Printf("%s, %s, %s\n", a.Grantee.Type, a.Grantee.ID, a.Permission)
}

24
example/object/getAnonymous.go

@ -11,6 +11,25 @@ import (
"github.com/tencentyun/cos-go-sdk-v5"
)
func log_status(err error) {
if err == nil {
return
}
if cos.IsNotFoundError(err) {
// WARN
fmt.Println("WARN: Resource is not existed")
} else if e, ok := cos.IsCOSError(err); ok {
fmt.Printf("ERROR: Code: %v\n", e.Code)
fmt.Printf("ERROR: Message: %v\n", e.Message)
fmt.Printf("ERROR: Resource: %v\n", e.Resource)
fmt.Printf("ERROR: RequestId: %v\n", e.RequestID)
// ERROR
} else {
fmt.Printf("ERROR: %v\n", err)
// ERROR
}
}
func upload(c *cos.Client, name string) {
f := strings.NewReader("test")
f = strings.NewReader("test xxx")
@ -35,10 +54,7 @@ func main() {
upload(c, name)
resp, err := c.Object.Get(context.Background(), name, nil)
if err != nil {
panic(err)
return
}
log_status(err)
bs, _ := ioutil.ReadAll(resp.Body)
defer resp.Body.Close()
fmt.Printf("%s\n", string(bs))

32
example/object/getByPresignedURL.go

@ -14,6 +14,25 @@ import (
"github.com/tencentyun/cos-go-sdk-v5/debug"
)
func log_status(err error) {
if err == nil {
return
}
if cos.IsNotFoundError(err) {
// WARN
fmt.Println("WARN: Resource is not existed")
} else if e, ok := cos.IsCOSError(err); ok {
fmt.Printf("ERROR: Code: %v\n", e.Code)
fmt.Printf("ERROR: Message: %v\n", e.Message)
fmt.Printf("ERROR: Resource: %v\n", e.Resource)
fmt.Printf("ERROR: RequestId: %v\n", e.RequestID)
// ERROR
} else {
fmt.Printf("ERROR: %v\n", err)
// ERROR
}
}
func main() {
ak := os.Getenv("COS_SECRETID")
sk := os.Getenv("COS_SECRETKEY")
@ -38,22 +57,17 @@ func main() {
// Normal header way to get object
resp, err := c.Object.Get(ctx, name, nil)
if err != nil {
panic(err)
}
log_status(err)
bs, _ := ioutil.ReadAll(resp.Body)
resp.Body.Close()
// Get presigned
presignedURL, err := c.Object.GetPresignedURL(ctx, http.MethodGet, name, ak, sk, time.Hour, nil)
if err != nil {
panic(err)
}
log_status(err)
// Get object by presinged url
resp2, err := http.Get(presignedURL.String())
if err != nil {
panic(err)
}
log_status(err)
bs2, _ := ioutil.ReadAll(resp2.Body)
resp2.Body.Close()
fmt.Printf("result2 is : %s\n", string(bs2))

24
example/object/head.go

@ -2,6 +2,7 @@ package main
import (
"context"
"fmt"
"net/url"
"os"
@ -11,6 +12,25 @@ import (
"github.com/tencentyun/cos-go-sdk-v5/debug"
)
func log_status(err error) {
if err == nil {
return
}
if cos.IsNotFoundError(err) {
// WARN
fmt.Println("WARN: Resource is not existed")
} else if e, ok := cos.IsCOSError(err); ok {
fmt.Printf("ERROR: Code: %v\n", e.Code)
fmt.Printf("ERROR: Message: %v\n", e.Message)
fmt.Printf("ERROR: Resource: %v\n", e.Resource)
fmt.Printf("ERROR: RequestId: %v\n", e.RequestID)
// ERROR
} else {
fmt.Printf("ERROR: %v\n", err)
// ERROR
}
}
func main() {
u, _ := url.Parse("https://test-1253846586.cos.ap-guangzhou.myqcloud.com")
b := &cos.BaseURL{BucketURL: u}
@ -29,7 +49,5 @@ func main() {
name := "test/hello.txt"
_, err := c.Object.Head(context.Background(), name, nil)
if err != nil {
panic(err)
}
log_status(err)
}

23
example/object/initiateMultipartUpload.go

@ -13,6 +13,25 @@ import (
"github.com/tencentyun/cos-go-sdk-v5/debug"
)
func log_status(err error) {
if err == nil {
return
}
if cos.IsNotFoundError(err) {
// WARN
fmt.Println("WARN: Resource is not existed")
} else if e, ok := cos.IsCOSError(err); ok {
fmt.Printf("ERROR: Code: %v\n", e.Code)
fmt.Printf("ERROR: Message: %v\n", e.Message)
fmt.Printf("ERROR: Resource: %v\n", e.Resource)
fmt.Printf("ERROR: RequestId: %v\n", e.RequestID)
// ERROR
} else {
fmt.Printf("ERROR: %v\n", err)
// ERROR
}
}
func main() {
u, _ := url.Parse("https://test-1253846586.cos.ap-guangzhou.myqcloud.com")
b := &cos.BaseURL{BucketURL: u}
@ -31,8 +50,6 @@ func main() {
name := "test_multipart" + time.Now().Format(time.RFC3339)
v, _, err := c.Object.InitiateMultipartUpload(context.Background(), name, nil)
if err != nil {
panic(err)
}
log_status(err)
fmt.Printf("%s\n", v.UploadID)
}

31
example/object/listParts.go

@ -14,11 +14,28 @@ import (
"github.com/tencentyun/cos-go-sdk-v5/debug"
)
func log_status(err error) {
if err == nil {
return
}
if cos.IsNotFoundError(err) {
// WARN
fmt.Println("WARN: Resource is not existed")
} else if e, ok := cos.IsCOSError(err); ok {
fmt.Printf("ERROR: Code: %v\n", e.Code)
fmt.Printf("ERROR: Message: %v\n", e.Message)
fmt.Printf("ERROR: Resource: %v\n", e.Resource)
fmt.Printf("ERROR: RequestId: %v\n", e.RequestID)
// ERROR
} else {
fmt.Printf("ERROR: %v\n", err)
// ERROR
}
}
func initUpload(c *cos.Client, name string) *cos.InitiateMultipartUploadResult {
v, _, err := c.Object.InitiateMultipartUpload(context.Background(), name, nil)
if err != nil {
panic(err)
}
log_status(err)
fmt.Printf("%#v\n", v)
return v
}
@ -27,7 +44,7 @@ func uploadPart(c *cos.Client, name string, uploadID string, blockSize, n int) s
b := make([]byte, blockSize)
if _, err := rand.Read(b); err != nil {
panic(err)
log_status(err)
}
s := fmt.Sprintf("%X", b)
f := strings.NewReader(s)
@ -35,9 +52,7 @@ func uploadPart(c *cos.Client, name string, uploadID string, blockSize, n int) s
resp, err := c.Object.UploadPart(
context.Background(), name, uploadID, n, f, nil,
)
if err != nil {
panic(err)
}
log_status(err)
fmt.Printf("%s\n", resp.Status)
return resp.Header.Get("Etag")
}
@ -73,7 +88,7 @@ func main() {
// }
v, _, err := c.Object.ListParts(ctx, name, uploadID, nil)
if err != nil {
panic(err)
log_status(err)
return
}
for _, p := range v.Parts {

26
example/object/options.go

@ -2,6 +2,7 @@ package main
import (
"context"
"fmt"
"net/url"
"os"
@ -11,6 +12,25 @@ import (
"github.com/tencentyun/cos-go-sdk-v5/debug"
)
func log_status(err error) {
if err == nil {
return
}
if cos.IsNotFoundError(err) {
// WARN
fmt.Println("WARN: Resource is not existed")
} else if e, ok := cos.IsCOSError(err); ok {
fmt.Printf("ERROR: Code: %v\n", e.Code)
fmt.Printf("ERROR: Message: %v\n", e.Message)
fmt.Printf("ERROR: Resource: %v\n", e.Resource)
fmt.Printf("ERROR: RequestId: %v\n", e.RequestID)
// ERROR
} else {
fmt.Printf("ERROR: %v\n", err)
// ERROR
}
}
func main() {
u, _ := url.Parse("https://test-1253846586.cos.ap-guangzhou.myqcloud.com")
b := &cos.BaseURL{BucketURL: u}
@ -29,11 +49,9 @@ func main() {
name := "test/hello.txt"
opt := &cos.ObjectOptionsOptions{
Origin: "http://www.qq.com",
Origin: "http://www.qq.com",
AccessControlRequestMethod: "PUT",
}
_, err := c.Object.Options(context.Background(), name, opt)
if err != nil {
panic(err)
}
log_status(err)
}

44
example/object/presigned_url_with_token.go

@ -0,0 +1,44 @@
package main
import (
"context"
"fmt"
"net/http"
"net/url"
"os"
"time"
"github.com/tencentyun/cos-go-sdk-v5"
)
type URLToken struct {
SessionToken string `url:"x-cos-security-token,omitempty" header:"-"`
}
func main() {
// 替换成您的临时密钥
tak := os.Getenv("COS_SECRETID")
tsk := os.Getenv("COS_SECRETKEY")
token := &URLToken{
SessionToken: "<token>",
}
u, _ := url.Parse("https://test-1259654469.cos.ap-guangzhou.myqcloud.com")
b := &cos.BaseURL{BucketURL: u}
c := cos.NewClient(b, &http.Client{})
name := "exampleobject"
ctx := context.Background()
// Get presigned
presignedURL, err := c.Object.GetPresignedURL(ctx, http.MethodGet, name, tak, tsk, time.Hour, token)
if err != nil {
fmt.Printf("Error: %v\n", err)
return
}
// Get object by presinged url
_, err = http.Get(presignedURL.String())
if err != nil {
fmt.Printf("Error: %v\n", err)
}
fmt.Println(presignedURL.String())
}

35
example/object/put.go

@ -2,6 +2,7 @@ package main
import (
"context"
"fmt"
"net/url"
"os"
"strings"
@ -12,8 +13,27 @@ import (
"github.com/tencentyun/cos-go-sdk-v5/debug"
)
func log_status(err error) {
if err == nil {
return
}
if cos.IsNotFoundError(err) {
// WARN
fmt.Println("WARN: Resource is not existed")
} else if e, ok := cos.IsCOSError(err); ok {
fmt.Printf("ERROR: Code: %v\n", e.Code)
fmt.Printf("ERROR: Message: %v\n", e.Message)
fmt.Printf("ERROR: Resource: %v\n", e.Resource)
fmt.Printf("ERROR: RequestId: %v\n", e.RequestID)
// ERROR
} else {
fmt.Printf("ERROR: %v\n", err)
// ERROR
}
}
func main() {
u, _ := url.Parse("https://test-1253846586.cos.ap-guangzhou.myqcloud.com")
u, _ := url.Parse("https://test-1259654469.cos.ap-guangzhou.myqcloud.com")
b := &cos.BaseURL{BucketURL: u}
c := cos.NewClient(b, &http.Client{
Transport: &cos.AuthorizationTransport{
@ -34,9 +54,7 @@ func main() {
f := strings.NewReader("test")
_, err := c.Object.Put(context.Background(), name, f, nil)
if err != nil {
panic(err)
}
log_status(err)
// Case2 put object with the options
name = "test/put_option.go"
@ -51,14 +69,9 @@ func main() {
},
}
_, err = c.Object.Put(context.Background(), name, f, opt)
if err != nil {
panic(err)
}
log_status(err)
// Case3 put object by local file path
_, err = c.Object.PutFromFile(context.Background(), name, "./test", nil)
if err != nil {
panic(err)
}
log_status(err)
}

28
example/object/putACL.go

@ -2,6 +2,7 @@ package main
import (
"context"
"fmt"
"net/url"
"os"
@ -11,6 +12,25 @@ import (
"github.com/tencentyun/cos-go-sdk-v5/debug"
)
func log_status(err error) {
if err == nil {
return
}
if cos.IsNotFoundError(err) {
// WARN
fmt.Println("WARN: Resource is not existed")
} else if e, ok := cos.IsCOSError(err); ok {
fmt.Printf("ERROR: Code: %v\n", e.Code)
fmt.Printf("ERROR: Message: %v\n", e.Message)
fmt.Printf("ERROR: Resource: %v\n", e.Resource)
fmt.Printf("ERROR: RequestId: %v\n", e.RequestID)
// ERROR
} else {
fmt.Printf("ERROR: %v\n", err)
// ERROR
}
}
func main() {
u, _ := url.Parse("https://test-1253846586.cos.ap-guangzhou.myqcloud.com")
b := &cos.BaseURL{BucketURL: u}
@ -34,9 +54,7 @@ func main() {
}
name := "test/hello.txt"
_, err := c.Object.PutACL(context.Background(), name, opt)
if err != nil {
panic(err)
}
log_status(err)
// with body
opt = &cos.ObjectPutACLOptions{
@ -58,7 +76,5 @@ func main() {
}
_, err = c.Object.PutACL(context.Background(), name, opt)
if err != nil {
panic(err)
}
log_status(err)
}

24
example/object/restore.go

@ -2,6 +2,7 @@ package main
import (
"context"
"fmt"
"net/http"
"net/url"
"os"
@ -10,6 +11,25 @@ import (
"github.com/tencentyun/cos-go-sdk-v5/debug"
)
func log_status(err error) {
if err == nil {
return
}
if cos.IsNotFoundError(err) {
// WARN
fmt.Println("WARN: Resource is not existed")
} else if e, ok := cos.IsCOSError(err); ok {
fmt.Printf("ERROR: Code: %v\n", e.Code)
fmt.Printf("ERROR: Message: %v\n", e.Message)
fmt.Printf("ERROR: Resource: %v\n", e.Resource)
fmt.Printf("ERROR: RequestId: %v\n", e.RequestID)
// ERROR
} else {
fmt.Printf("ERROR: %v\n", err)
// ERROR
}
}
func main() {
u, _ := url.Parse("https://test-1253846586.cos.ap-guangzhou.myqcloud.com")
b := &cos.BaseURL{BucketURL: u}
@ -35,7 +55,5 @@ func main() {
}
name := "archivetest"
_, err := c.Object.PostRestore(context.Background(), name, opt)
if err != nil {
panic(err)
}
log_status(err)
}

81
example/object/sse_c.go

@ -0,0 +1,81 @@
package main
import (
"context"
"errors"
"fmt"
"io/ioutil"
"net/http"
"net/url"
"os"
"strings"
"github.com/tencentyun/cos-go-sdk-v5"
"github.com/tencentyun/cos-go-sdk-v5/debug"
)
func log_status(err error) {
if err == nil {
return
}
if cos.IsNotFoundError(err) {
// WARN
fmt.Println("WARN: Resource is not existed")
} else if e, ok := cos.IsCOSError(err); ok {
fmt.Printf("ERROR: Code: %v\n", e.Code)
fmt.Printf("ERROR: Message: %v\n", e.Message)
fmt.Printf("ERROR: Resource: %v\n", e.Resource)
fmt.Printf("ERROR: RequestId: %v\n", e.RequestID)
// ERROR
} else {
fmt.Printf("ERROR: %v\n", err)
// ERROR
}
}
func main() {
u, _ := url.Parse("https://testcd-1259654469.cos.ap-chengdu.myqcloud.com")
b := &cos.BaseURL{BucketURL: u}
c := cos.NewClient(b, &http.Client{
Transport: &cos.AuthorizationTransport{
SecretID: os.Getenv("COS_SECRETID"),
SecretKey: os.Getenv("COS_SECRETKEY"),
Transport: &debug.DebugRequestTransport{
RequestHeader: true,
// Notice when put a large file and set need the request body, might happend out of memory error.
RequestBody: false,
ResponseHeader: true,
ResponseBody: true,
},
},
})
opt := &cos.ObjectPutOptions{
ObjectPutHeaderOptions: &cos.ObjectPutHeaderOptions{
ContentType: "text/html",
XCosSSECustomerAglo: "AES256",
XCosSSECustomerKey: "MDEyMzQ1Njc4OUFCQ0RFRjAxMjM0NTY3ODlBQkNERUY=",
XCosSSECustomerKeyMD5: "U5L61r7jcwdNvT7frmUG8g==",
},
ACLHeaderOptions: &cos.ACLHeaderOptions{},
}
name := "PutFromGoWithSSE-C"
content := "Put Object From Go With SSE-C"
f := strings.NewReader(content)
_, err := c.Object.Put(context.Background(), name, f, opt)
log_status(err)
getopt := &cos.ObjectGetOptions{
XCosSSECustomerAglo: "AES256",
XCosSSECustomerKey: "MDEyMzQ1Njc4OUFCQ0RFRjAxMjM0NTY3ODlBQkNERUY=",
XCosSSECustomerKeyMD5: "U5L61r7jcwdNvT7frmUG8g==",
}
var resp *cos.Response
resp, err = c.Object.Get(context.Background(), name, getopt)
log_status(err)
bodyBytes, _ := ioutil.ReadAll(resp.Body)
bodyContent := string(bodyBytes)
if bodyContent != content {
log_status(errors.New("Content inconsistency"))
}
}

75
example/object/sse_cos.go

@ -0,0 +1,75 @@
package main
import (
"context"
"errors"
"fmt"
"io/ioutil"
"net/http"
"net/url"
"os"
"strings"
"github.com/tencentyun/cos-go-sdk-v5"
"github.com/tencentyun/cos-go-sdk-v5/debug"
)
func log_status(err error) {
if err == nil {
return
}
if cos.IsNotFoundError(err) {
// WARN
fmt.Println("WARN: Resource is not existed")
} else if e, ok := cos.IsCOSError(err); ok {
fmt.Printf("ERROR: Code: %v\n", e.Code)
fmt.Printf("ERROR: Message: %v\n", e.Message)
fmt.Printf("ERROR: Resource: %v\n", e.Resource)
fmt.Printf("ERROR: RequestId: %v\n", e.RequestID)
// ERROR
} else {
fmt.Printf("ERROR: %v\n", err)
// ERROR
}
}
func main() {
u, _ := url.Parse("https://test-1259654469.cos.ap-guangzhou.myqcloud.com")
b := &cos.BaseURL{BucketURL: u}
c := cos.NewClient(b, &http.Client{
Transport: &cos.AuthorizationTransport{
SecretID: os.Getenv("COS_SECRETID"),
SecretKey: os.Getenv("COS_SECRETKEY"),
Transport: &debug.DebugRequestTransport{
RequestHeader: true,
// Notice when put a large file and set need the request body, might happend out of memory error.
RequestBody: false,
ResponseHeader: true,
ResponseBody: true,
},
},
})
opt := &cos.ObjectPutOptions{
ObjectPutHeaderOptions: &cos.ObjectPutHeaderOptions{
ContentType: "text/html",
XCosServerSideEncryption: "AES256",
},
ACLHeaderOptions: &cos.ACLHeaderOptions{},
}
name := "PutFromGoWithSSE-COS"
content := "Put Object From Go With SSE-COS"
f := strings.NewReader(content)
_, err := c.Object.Put(context.Background(), name, f, opt)
log_status(err)
getopt := &cos.ObjectGetOptions{}
var resp *cos.Response
resp, err = c.Object.Get(context.Background(), name, getopt)
log_status(err)
bodyBytes, _ := ioutil.ReadAll(resp.Body)
bodyContent := string(bodyBytes)
if bodyContent != content {
log_status(errors.New("Content inconsistency"))
}
}

23
example/object/upload.go

@ -12,6 +12,25 @@ import (
"github.com/tencentyun/cos-go-sdk-v5/debug"
)
func log_status(err error) {
if err == nil {
return
}
if cos.IsNotFoundError(err) {
// WARN
fmt.Println("WARN: Resource is not existed")
} else if e, ok := cos.IsCOSError(err); ok {
fmt.Printf("ERROR: Code: %v\n", e.Code)
fmt.Printf("ERROR: Message: %v\n", e.Message)
fmt.Printf("ERROR: Resource: %v\n", e.Resource)
fmt.Printf("ERROR: RequestId: %v\n", e.RequestID)
// ERROR
} else {
fmt.Printf("ERROR: %v\n", err)
// ERROR
}
}
func main() {
u, _ := url.Parse("https://test-1259654469.cos.ap-guangzhou.myqcloud.com")
b := &cos.BaseURL{BucketURL: u}
@ -33,8 +52,6 @@ func main() {
v, _, err := c.Object.Upload(
context.Background(), "gomulput1G", "./test1G", nil,
)
if err != nil {
panic(err)
}
log_status(err)
fmt.Println(v)
}

29
example/object/uploadFile.go

@ -13,6 +13,25 @@ import (
"github.com/tencentyun/cos-go-sdk-v5/debug"
)
func log_status(err error) {
if err == nil {
return
}
if cos.IsNotFoundError(err) {
// WARN
fmt.Println("WARN: Resource is not existed")
} else if e, ok := cos.IsCOSError(err); ok {
fmt.Printf("ERROR: Code: %v\n", e.Code)
fmt.Printf("ERROR: Message: %v\n", e.Message)
fmt.Printf("ERROR: Resource: %v\n", e.Resource)
fmt.Printf("ERROR: RequestId: %v\n", e.RequestID)
// ERROR
} else {
fmt.Printf("ERROR: %v\n", err)
// ERROR
}
}
func main() {
u, _ := url.Parse("https://test-1253846586.cos.ap-guangzhou.myqcloud.com")
b := &cos.BaseURL{BucketURL: u}
@ -32,11 +51,13 @@ func main() {
name := "test/uploadFile.go"
f, err := os.Open(os.Args[0])
if err != nil {
panic(err)
log_status(err)
return
}
s, err := f.Stat()
if err != nil {
panic(err)
log_status(err)
return
}
fmt.Println(s.Size())
opt := &cos.ObjectPutOptions{
@ -47,7 +68,5 @@ func main() {
//opt.ContentLength = int(s.Size())
_, err = c.Object.Put(context.Background(), name, f, opt)
if err != nil {
panic(err)
}
log_status(err)
}

27
example/object/uploadPart.go

@ -14,11 +14,28 @@ import (
"github.com/tencentyun/cos-go-sdk-v5/debug"
)
func log_status(err error) {
if err == nil {
return
}
if cos.IsNotFoundError(err) {
// WARN
fmt.Println("WARN: Resource is not existed")
} else if e, ok := cos.IsCOSError(err); ok {
fmt.Printf("ERROR: Code: %v\n", e.Code)
fmt.Printf("ERROR: Message: %v\n", e.Message)
fmt.Printf("ERROR: Resource: %v\n", e.Resource)
fmt.Printf("ERROR: RequestId: %v\n", e.RequestID)
// ERROR
} else {
fmt.Printf("ERROR: %v\n", err)
// ERROR
}
}
func initUpload(c *cos.Client, name string) *cos.InitiateMultipartUploadResult {
v, _, err := c.Object.InitiateMultipartUpload(context.Background(), name, nil)
if err != nil {
panic(err)
}
log_status(err)
fmt.Printf("%#v\n", v)
return v
}
@ -47,7 +64,5 @@ func main() {
_, err := c.Object.UploadPart(
context.Background(), name, uploadID, 1, f, nil,
)
if err != nil {
panic(err)
}
log_status(err)
}
Loading…
Cancel
Save