Skip to content

Commit 73c440c

Browse files
authored
Merge pull request #107 from agin719/cos-v4-dev
Cos v4 dev
2 parents 50905a1 + 685c58a commit 73c440c

File tree

4 files changed

+177
-1
lines changed

4 files changed

+177
-1
lines changed

ci.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ import (
44
"context"
55
"encoding/json"
66
"encoding/xml"
7+
"io"
78
"net/http"
9+
"os"
810
)
911

1012
type CIService service
@@ -201,3 +203,41 @@ func (s *CIService) GetVideoAuditingJob(ctx context.Context, jobid string) (*Get
201203
resp, err := s.client.send(ctx, &sendOpt)
202204
return &res, resp, err
203205
}
206+
207+
// ci put https://cloud.tencent.com/document/product/460/18147
208+
func (s *CIService) Put(ctx context.Context, name string, r io.Reader, opt *ObjectPutOptions) (*ImageProcessResult, *Response, error) {
209+
if err := CheckReaderLen(r); err != nil {
210+
return nil, nil, err
211+
}
212+
if opt != nil && opt.Listener != nil {
213+
totalBytes, err := GetReaderLen(r)
214+
if err != nil {
215+
return nil, nil, err
216+
}
217+
r = TeeReader(r, nil, totalBytes, opt.Listener)
218+
}
219+
220+
var res ImageProcessResult
221+
sendOpt := sendOptions{
222+
baseURL: s.client.BaseURL.BucketURL,
223+
uri: "/" + encodeURIComponent(name),
224+
method: http.MethodPut,
225+
body: r,
226+
optHeader: opt,
227+
result: &res,
228+
}
229+
resp, err := s.client.send(ctx, &sendOpt)
230+
231+
return &res, resp, err
232+
}
233+
234+
// ci put object from local file
235+
func (s *CIService) PutFromFile(ctx context.Context, name string, filePath string, opt *ObjectPutOptions) (*ImageProcessResult, *Response, error) {
236+
fd, err := os.Open(filePath)
237+
if err != nil {
238+
return nil, nil, err
239+
}
240+
defer fd.Close()
241+
242+
return s.Put(ctx, name, fd, opt)
243+
}

example/CI/ci_image_process.go

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package main
2+
3+
import (
4+
"context"
5+
"fmt"
6+
"net/http"
7+
"net/url"
8+
"os"
9+
10+
"github.com/tencentyun/cos-go-sdk-v5"
11+
"github.com/tencentyun/cos-go-sdk-v5/debug"
12+
)
13+
14+
func log_status(err error) {
15+
if err == nil {
16+
return
17+
}
18+
if cos.IsNotFoundError(err) {
19+
// WARN
20+
fmt.Println("WARN: Resource is not existed")
21+
} else if e, ok := cos.IsCOSError(err); ok {
22+
fmt.Printf("ERROR: Code: %v\n", e.Code)
23+
fmt.Printf("ERROR: Message: %v\n", e.Message)
24+
fmt.Printf("ERROR: Resource: %v\n", e.Resource)
25+
fmt.Printf("ERROR: RequestId: %v\n", e.RequestID)
26+
// ERROR
27+
} else {
28+
fmt.Printf("ERROR: %v\n", err)
29+
// ERROR
30+
}
31+
}
32+
33+
func main() {
34+
u, _ := url.Parse("https://test-1259654469.cos.ap-guangzhou.myqcloud.com")
35+
b := &cos.BaseURL{BucketURL: u}
36+
c := cos.NewClient(b, &http.Client{
37+
Transport: &cos.AuthorizationTransport{
38+
SecretID: os.Getenv("COS_SECRETID"),
39+
SecretKey: os.Getenv("COS_SECRETKEY"),
40+
Transport: &debug.DebugRequestTransport{
41+
RequestHeader: true,
42+
// Notice when put a large file and set need the request body, might happend out of memory error.
43+
RequestBody: false,
44+
ResponseHeader: true,
45+
ResponseBody: true,
46+
},
47+
},
48+
})
49+
50+
opt := &cos.ImageProcessOptions{
51+
IsPicInfo: 1,
52+
Rules: []cos.PicOperationsRules{
53+
{
54+
FileId: "format.jpg",
55+
Rule: "imageView2/format/png",
56+
},
57+
},
58+
}
59+
name := "test.jpg"
60+
res, _, err := c.CI.ImageProcess(context.Background(), name, opt)
61+
log_status(err)
62+
fmt.Printf("%+v\n", res)
63+
}

example/CI/ci_put.go

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
package main
2+
3+
import (
4+
"context"
5+
"fmt"
6+
"net/http"
7+
"net/url"
8+
"os"
9+
10+
"github.com/tencentyun/cos-go-sdk-v5"
11+
"github.com/tencentyun/cos-go-sdk-v5/debug"
12+
)
13+
14+
func log_status(err error) {
15+
if err == nil {
16+
return
17+
}
18+
if cos.IsNotFoundError(err) {
19+
// WARN
20+
fmt.Println("WARN: Resource is not existed")
21+
} else if e, ok := cos.IsCOSError(err); ok {
22+
fmt.Printf("ERROR: Code: %v\n", e.Code)
23+
fmt.Printf("ERROR: Message: %v\n", e.Message)
24+
fmt.Printf("ERROR: Resource: %v\n", e.Resource)
25+
fmt.Printf("ERROR: RequestId: %v\n", e.RequestID)
26+
// ERROR
27+
} else {
28+
fmt.Printf("ERROR: %v\n", err)
29+
// ERROR
30+
}
31+
}
32+
33+
func main() {
34+
u, _ := url.Parse("https://test-1259654469.cos.ap-guangzhou.myqcloud.com")
35+
b := &cos.BaseURL{BucketURL: u}
36+
c := cos.NewClient(b, &http.Client{
37+
Transport: &cos.AuthorizationTransport{
38+
SecretID: os.Getenv("COS_SECRETID"),
39+
SecretKey: os.Getenv("COS_SECRETKEY"),
40+
Transport: &debug.DebugRequestTransport{
41+
RequestHeader: true,
42+
// Notice when put a large file and set need the request body, might happend out of memory error.
43+
RequestBody: false,
44+
ResponseHeader: true,
45+
ResponseBody: true,
46+
},
47+
},
48+
})
49+
50+
opt := &cos.ObjectPutOptions{
51+
nil,
52+
&cos.ObjectPutHeaderOptions{
53+
XOptionHeader: &http.Header{},
54+
},
55+
}
56+
pic := &cos.PicOperations{
57+
IsPicInfo: 1,
58+
Rules: []cos.PicOperationsRules{
59+
{
60+
FileId: "format.jpg",
61+
Rule: "imageView2/format/png",
62+
},
63+
},
64+
}
65+
opt.XOptionHeader.Add("Pic-Operations", cos.EncodePicOperations(pic))
66+
name := "test.jpg"
67+
local_filename := "./test.jpg"
68+
res, _, err := c.CI.PutFromFile(context.Background(), name, local_filename, opt)
69+
log_status(err)
70+
fmt.Printf("%+v\n", res)
71+
fmt.Printf("%+v\n", res.OriginalInfo)
72+
fmt.Printf("%+v\n", res.ProcessResults)
73+
}

object_select.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ type JSONOutputSerialization struct {
3939
}
4040

4141
type CSVOutputSerialization struct {
42-
QuoteFileds string `xml:"QuoteFileds,omitempty"`
42+
QuoteFields string `xml:"QuoteFields,omitempty"`
4343
RecordDelimiter string `xml:"RecordDelimiter,omitempty"`
4444
FieldDelimiter string `xml:"FieldDelimiter,omitempty"`
4545
QuoteCharacter string `xml:"QuoteCharacter,omitempty"`

0 commit comments

Comments
 (0)