MCPcopy Create free account
hub / github.com/UESTCByteDance/ByteRhythm / UploadJPG

Function UploadJPG

util/upload.go:39–68  ·  view source on GitHub ↗
(imgPath string, videoUrl string)

Source from the content-addressed store, hash-verified

37}
38
39func UploadJPG(imgPath string, videoUrl string) string {
40 config.Init()
41
42 videoName := strings.Split(strings.Replace(videoUrl, config.Domain+"/", "", -1), ".")[0]
43 key := fmt.Sprintf("%s.%s", videoName+"_cover", "jpg")
44
45 putPolicy := storage.PutPolicy{
46 Scope: config.Bucket,
47 }
48 mac := qbox.NewMac(config.AccessKey, config.SecretKey)
49 upToken := putPolicy.UploadToken(mac)
50 cfg := storage.Config{}
51
52 // 构建表单上传的对象
53 formUploader := storage.NewFormUploader(&cfg)
54 ret := storage.PutRet{}
55
56 // 可选配置
57 putExtra := storage.PutExtra{
58 Params: map[string]string{
59 "x:name": "github logo",
60 },
61 }
62 err := formUploader.PutFile(context.Background(), &ret, upToken, key, imgPath, &putExtra)
63 if err != nil {
64 fmt.Println(err)
65 return ""
66 }
67 return fmt.Sprintf("%s/%s", config.Domain, ret.Key)
68}

Callers 1

VideoMQ2DBFunction · 0.92

Calls 1

InitFunction · 0.92

Tested by

no test coverage detected