committed by
							
								
								GitHub
							
						
					
				
				
				  
				  No known key found for this signature in database
				  
				  	
						GPG Key ID: 4AEE18F83AFDEB23
				  	
				  
				
			
		
		
		
	
				 4 changed files with 298 additions and 0 deletions
			
			
		- 
					122ci_media.go
 - 
					58example/CI/media_process/describe_media_buckets.go
 - 
					53example/CI/media_process/get_media_info.go
 - 
					65example/CI/media_process/get_snapshot.go
 
@ -0,0 +1,58 @@ | 
			
		|||||
 | 
				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") | 
			
		||||
 | 
					// DescirbeMediaBuckets 需要设置 CIURL 为 ci.<Region>.myqcloud.com
 | 
			
		||||
 | 
					cu, _ := url.Parse("https://ci.ap-guangzhou.myqcloud.com") | 
			
		||||
 | 
					b := &cos.BaseURL{BucketURL: u, CIURL: cu} | 
			
		||||
 | 
					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:    true, | 
			
		||||
 | 
								ResponseHeader: true, | 
			
		||||
 | 
								ResponseBody:   true, | 
			
		||||
 | 
							}, | 
			
		||||
 | 
						}, | 
			
		||||
 | 
					}) | 
			
		||||
 | 
				
 | 
			
		||||
 | 
					opt := &cos.DescribeMediaProcessBucketsOptions{ | 
			
		||||
 | 
						Regions: "ap-guangzhou", | 
			
		||||
 | 
					} | 
			
		||||
 | 
					res, _, err := c.CI.DescribeMediaProcessBuckets(context.Background(), opt) | 
			
		||||
 | 
					log_status(err) | 
			
		||||
 | 
					fmt.Printf("res: %+v\n", res) | 
			
		||||
 | 
				} | 
			
		||||
@ -0,0 +1,53 @@ | 
			
		|||||
 | 
				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:    true, | 
			
		||||
 | 
								ResponseHeader: true, | 
			
		||||
 | 
								ResponseBody:   true, | 
			
		||||
 | 
							}, | 
			
		||||
 | 
						}, | 
			
		||||
 | 
					}) | 
			
		||||
 | 
				
 | 
			
		||||
 | 
					res, _, err := c.CI.GetMediaInfo(context.Background(), "test.mp4", nil) | 
			
		||||
 | 
					log_status(err) | 
			
		||||
 | 
					fmt.Printf("res: %+v\n", res) | 
			
		||||
 | 
				} | 
			
		||||
@ -0,0 +1,65 @@ | 
			
		|||||
 | 
				package main | 
			
		||||
 | 
				
 | 
			
		||||
 | 
				import ( | 
			
		||||
 | 
					"context" | 
			
		||||
 | 
					"fmt" | 
			
		||||
 | 
					"io" | 
			
		||||
 | 
					"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:    true, | 
			
		||||
 | 
								ResponseHeader: true, | 
			
		||||
 | 
								ResponseBody:   false, | 
			
		||||
 | 
							}, | 
			
		||||
 | 
						}, | 
			
		||||
 | 
					}) | 
			
		||||
 | 
				
 | 
			
		||||
 | 
					opt := &cos.GetSnapshotOptions{ | 
			
		||||
 | 
						Time: 1, | 
			
		||||
 | 
					} | 
			
		||||
 | 
					resp, err := c.CI.GetSnapshot(context.Background(), "test.mp4", opt) | 
			
		||||
 | 
					log_status(err) | 
			
		||||
 | 
					defer resp.Body.Close() | 
			
		||||
 | 
				
 | 
			
		||||
 | 
					fd, err := os.OpenFile("test.jpg", os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0660) | 
			
		||||
 | 
					if err != nil { | 
			
		||||
 | 
						log_status(err) | 
			
		||||
 | 
					} | 
			
		||||
 | 
					_, err = io.Copy(fd, resp.Body) | 
			
		||||
 | 
					fd.Close() | 
			
		||||
 | 
					log_status(err) | 
			
		||||
 | 
				} | 
			
		||||
						Write
						Preview
					
					
					Loading…
					
					Cancel
						Save
					
		Reference in new issue