正在显示
6 个修改的文件
包含
20 行增加
和
7 行删除
| @@ -22,7 +22,7 @@ type BuckObject struct { | @@ -22,7 +22,7 @@ type BuckObject struct { | ||
| 22 | } | 22 | } |
| 23 | 23 | ||
| 24 | // 创建视频上传凭证 | 24 | // 创建视频上传凭证 |
| 25 | -func CreateOssUpload(header *protocol.RequestHeader, MultipartForm *multipart.Form) (rsp interface{}, err error) { | 25 | +func CreateOssUpload(header *protocol.RequestHeader, MultipartForm *multipart.Form, disableRename bool) (rsp interface{}, err error) { |
| 26 | var objects []aliyun.Object | 26 | var objects []aliyun.Object |
| 27 | var listPath []BuckObject | 27 | var listPath []BuckObject |
| 28 | var bucket *oss.Bucket | 28 | var bucket *oss.Bucket |
| @@ -42,7 +42,7 @@ func CreateOssUpload(header *protocol.RequestHeader, MultipartForm *multipart.Fo | @@ -42,7 +42,7 @@ func CreateOssUpload(header *protocol.RequestHeader, MultipartForm *multipart.Fo | ||
| 42 | f.Close() | 42 | f.Close() |
| 43 | reader := bytes.NewBuffer(data) | 43 | reader := bytes.NewBuffer(data) |
| 44 | fileBase := filepath.Base(v[i].Filename) | 44 | fileBase := filepath.Base(v[i].Filename) |
| 45 | - key := utils.GetFileName(header.AppProject, aliyun.FileObject, fileBase) | 45 | + key := utils.GetFileName(header.AppProject, aliyun.FileObject, fileBase, disableRename) |
| 46 | objects = append(objects, aliyun.Object{ | 46 | objects = append(objects, aliyun.Object{ |
| 47 | Key: key, | 47 | Key: key, |
| 48 | Value: reader, | 48 | Value: reader, |
| @@ -19,6 +19,8 @@ type RequestHeader struct { | @@ -19,6 +19,8 @@ type RequestHeader struct { | ||
| 19 | 19 | ||
| 20 | requestId string //请求编号 md5 | 20 | requestId string //请求编号 md5 |
| 21 | reqIndex int64 //请求链序号 | 21 | reqIndex int64 //请求链序号 |
| 22 | + | ||
| 23 | + KeepFileName bool // 保存文件名 (上传) | ||
| 22 | } | 24 | } |
| 23 | 25 | ||
| 24 | func (reqHead *RequestHeader) SetRequestId(addString ...string) { | 26 | func (reqHead *RequestHeader) SetRequestId(addString ...string) { |
| @@ -36,8 +36,9 @@ func IsFile(path string) bool { | @@ -36,8 +36,9 @@ func IsFile(path string) bool { | ||
| 36 | return !IsDir(path) | 36 | return !IsDir(path) |
| 37 | } | 37 | } |
| 38 | 38 | ||
| 39 | -//fileType: video voice image | ||
| 40 | -func GetFileName(projectName, fileType string, filename string) string { | 39 | +// fileType: video voice image |
| 40 | +func GetFileName(projectName, fileType string, filename string, args ...interface{}) string { | ||
| 41 | + var oldFileName = filename | ||
| 41 | date := comm_time.GetTimeByYyyymmdd() | 42 | date := comm_time.GetTimeByYyyymmdd() |
| 42 | subfix := path.Ext(filename) | 43 | subfix := path.Ext(filename) |
| 43 | if len(projectName) == 0 { | 44 | if len(projectName) == 0 { |
| @@ -45,6 +46,9 @@ func GetFileName(projectName, fileType string, filename string) string { | @@ -45,6 +46,9 @@ func GetFileName(projectName, fileType string, filename string) string { | ||
| 45 | } | 46 | } |
| 46 | prefix := fmt.Sprintf("%v_%v", time.Now().Unix(), common.RandomString(32)) | 47 | prefix := fmt.Sprintf("%v_%v", time.Now().Unix(), common.RandomString(32)) |
| 47 | filename = fmt.Sprintf("%v%v", prefix, subfix) | 48 | filename = fmt.Sprintf("%v%v", prefix, subfix) |
| 49 | + if len(args) > 0 && args[0].(bool) { | ||
| 50 | + filename = oldFileName | ||
| 51 | + } | ||
| 48 | sourcePath := fmt.Sprintf("%v/%v/%v/%v/%v", projectName, beego.BConfig.RunMode, date, fileType, filename) | 52 | sourcePath := fmt.Sprintf("%v/%v/%v/%v/%v", projectName, beego.BConfig.RunMode, date, fileType, filename) |
| 49 | return sourcePath | 53 | return sourcePath |
| 50 | } | 54 | } |
| @@ -208,7 +208,7 @@ func (this *VodController) PutObject() { | @@ -208,7 +208,7 @@ func (this *VodController) PutObject() { | ||
| 208 | }() | 208 | }() |
| 209 | 209 | ||
| 210 | header := controllers.GetRequestHeader(this.Ctx) | 210 | header := controllers.GetRequestHeader(this.Ctx) |
| 211 | - msg = domain.NewReturnResponse(oss.CreateOssUpload(header, this.Ctx.Request.MultipartForm)) | 211 | + msg = domain.NewReturnResponse(oss.CreateOssUpload(header, this.Ctx.Request.MultipartForm, false)) |
| 212 | } | 212 | } |
| 213 | 213 | ||
| 214 | // STS授权 CreateStsAuth | 214 | // STS授权 CreateStsAuth |
| @@ -8,6 +8,7 @@ import ( | @@ -8,6 +8,7 @@ import ( | ||
| 8 | "openapi/pkg/domain" | 8 | "openapi/pkg/domain" |
| 9 | "openapi/pkg/infrastructure/aliyun" | 9 | "openapi/pkg/infrastructure/aliyun" |
| 10 | "openapi/pkg/port/beego/controllers" | 10 | "openapi/pkg/port/beego/controllers" |
| 11 | + "strconv" | ||
| 11 | ) | 12 | ) |
| 12 | 13 | ||
| 13 | type VodController struct { | 14 | type VodController struct { |
| @@ -206,9 +207,14 @@ func (this *VodController) PutObject() { | @@ -206,9 +207,14 @@ func (this *VodController) PutObject() { | ||
| 206 | defer func() { | 207 | defer func() { |
| 207 | this.Resp(msg) | 208 | this.Resp(msg) |
| 208 | }() | 209 | }() |
| 209 | - | 210 | + var request = struct { |
| 211 | + DisableRename bool `json:"disableRename"` // 禁用重命名 | ||
| 212 | + }{} | ||
| 213 | + if val := this.Ctx.Input.Query("disableRename"); len(val) > 0 { | ||
| 214 | + request.DisableRename, _ = strconv.ParseBool(val) | ||
| 215 | + } | ||
| 210 | header := controllers.GetRequestHeader(this.Ctx) | 216 | header := controllers.GetRequestHeader(this.Ctx) |
| 211 | - msg = domain.NewReturnResponse(oss.CreateOssUpload(header, this.Ctx.Request.MultipartForm)) | 217 | + msg = domain.NewReturnResponse(oss.CreateOssUpload(header, this.Ctx.Request.MultipartForm, request.DisableRename)) |
| 212 | } | 218 | } |
| 213 | 219 | ||
| 214 | // STS授权 CreateStsAuth | 220 | // STS授权 CreateStsAuth |
| @@ -18,6 +18,7 @@ func init() { | @@ -18,6 +18,7 @@ func init() { | ||
| 18 | ) | 18 | ) |
| 19 | beego.SetStaticPath("/log", constant.LogFilePath) | 19 | beego.SetStaticPath("/log", constant.LogFilePath) |
| 20 | beego.Router("/v2/vod/createStsAuth", &v2.VodController{}, "Post:CreateStsAuth") | 20 | beego.Router("/v2/vod/createStsAuth", &v2.VodController{}, "Post:CreateStsAuth") |
| 21 | + beego.Router("/v2/vod/putObject", &v2.VodController{}, "Post:PutObject") | ||
| 21 | beego.AddNamespace(nsV1) | 22 | beego.AddNamespace(nsV1) |
| 22 | beego.InsertFilter("/*", beego.BeforeRouter, controllers.AllowCors()) | 23 | beego.InsertFilter("/*", beego.BeforeRouter, controllers.AllowCors()) |
| 23 | } | 24 | } |
-
请 注册 或 登录 后发表评论