update ci put & select
This commit is contained in:
40
ci.go
40
ci.go
@@ -4,7 +4,9 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"encoding/xml"
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
)
|
||||
|
||||
type CIService service
|
||||
@@ -201,3 +203,41 @@ func (s *CIService) GetVideoAuditingJob(ctx context.Context, jobid string) (*Get
|
||||
resp, err := s.client.send(ctx, &sendOpt)
|
||||
return &res, resp, err
|
||||
}
|
||||
|
||||
// ci put https://cloud.tencent.com/document/product/460/18147
|
||||
func (s *CIService) Put(ctx context.Context, name string, r io.Reader, opt *ObjectPutOptions) (*ImageProcessResult, *Response, error) {
|
||||
if err := CheckReaderLen(r); err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
if opt != nil && opt.Listener != nil {
|
||||
totalBytes, err := GetReaderLen(r)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
r = TeeReader(r, nil, totalBytes, opt.Listener)
|
||||
}
|
||||
|
||||
var res ImageProcessResult
|
||||
sendOpt := sendOptions{
|
||||
baseURL: s.client.BaseURL.BucketURL,
|
||||
uri: "/" + encodeURIComponent(name),
|
||||
method: http.MethodPut,
|
||||
body: r,
|
||||
optHeader: opt,
|
||||
result: &res,
|
||||
}
|
||||
resp, err := s.client.send(ctx, &sendOpt)
|
||||
|
||||
return &res, resp, err
|
||||
}
|
||||
|
||||
// ci put object from local file
|
||||
func (s *CIService) PutFromFile(ctx context.Context, name string, filePath string, opt *ObjectPutOptions) (*ImageProcessResult, *Response, error) {
|
||||
fd, err := os.Open(filePath)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
defer fd.Close()
|
||||
|
||||
return s.Put(ctx, name, fd, opt)
|
||||
}
|
||||
|
||||
63
example/CI/ci_image_process.go
Normal file
63
example/CI/ci_image_process.go
Normal file
@@ -0,0 +1,63 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
|
||||
"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.ImageProcessOptions{
|
||||
IsPicInfo: 1,
|
||||
Rules: []cos.PicOperationsRules{
|
||||
{
|
||||
FileId: "format.jpg",
|
||||
Rule: "imageView2/format/png",
|
||||
},
|
||||
},
|
||||
}
|
||||
name := "test.jpg"
|
||||
res, _, err := c.CI.ImageProcess(context.Background(), name, opt)
|
||||
log_status(err)
|
||||
fmt.Printf("%+v\n", res)
|
||||
}
|
||||
73
example/CI/ci_put.go
Normal file
73
example/CI/ci_put.go
Normal file
@@ -0,0 +1,73 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
|
||||
"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://jojoliang-batch-1253960454.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{
|
||||
nil,
|
||||
&cos.ObjectPutHeaderOptions{
|
||||
XOptionHeader: &http.Header{},
|
||||
},
|
||||
}
|
||||
pic := &cos.PicOperations{
|
||||
IsPicInfo: 1,
|
||||
Rules: []cos.PicOperationsRules{
|
||||
{
|
||||
FileId: "format.jpg",
|
||||
Rule: "imageView2/format/png",
|
||||
},
|
||||
},
|
||||
}
|
||||
opt.XOptionHeader.Add("Pic-Operations", cos.EncodePicOperations(pic))
|
||||
name := "test.jpg"
|
||||
local_filename := "./test.jpg"
|
||||
res, _, err := c.CI.PutFromFile(context.Background(), name, local_filename, opt)
|
||||
log_status(err)
|
||||
fmt.Printf("%+v\n", res)
|
||||
fmt.Printf("%+v\n", res.OriginalInfo)
|
||||
fmt.Printf("%+v\n", res.ProcessResults)
|
||||
}
|
||||
@@ -39,7 +39,7 @@ type JSONOutputSerialization struct {
|
||||
}
|
||||
|
||||
type CSVOutputSerialization struct {
|
||||
QuoteFileds string `xml:"QuoteFileds,omitempty"`
|
||||
QuoteFields string `xml:"QuoteFields,omitempty"`
|
||||
RecordDelimiter string `xml:"RecordDelimiter,omitempty"`
|
||||
FieldDelimiter string `xml:"FieldDelimiter,omitempty"`
|
||||
QuoteCharacter string `xml:"QuoteCharacter,omitempty"`
|
||||
|
||||
Reference in New Issue
Block a user