forked from all_user/stat_center
Initial commit
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
package fileApi
|
||||
|
||||
import (
|
||||
"stat/common/file"
|
||||
"stat/common/log"
|
||||
"stat/common/stdLog"
|
||||
"stat/statg"
|
||||
"strings"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// @Tags 文件上传
|
||||
// @Summary 文件上传
|
||||
// @Description 文件上传
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Security ApiKeyAuth
|
||||
// @Param file formData file true "文件数据"
|
||||
// @Success 200 {string}} string "成功"
|
||||
// @Failure 400 {string} string "失败"
|
||||
// @Router /api/stat/file/upload [POST]
|
||||
func FileUpload(ctx *gin.Context) {
|
||||
f, err := ctx.FormFile("file")
|
||||
if err != nil {
|
||||
stdLog.ServerJSON(ctx, stdLog.ParamError, err)
|
||||
return
|
||||
}
|
||||
// 上传到桶2
|
||||
data, err := file.PutObject(ctx, statg.Conf.ProxyUrl.FileRes, &file.FileObject{
|
||||
File: f,
|
||||
})
|
||||
if err != nil {
|
||||
stdLog.ServerJSON(ctx, stdLog.Failure, err.Error())
|
||||
} else {
|
||||
|
||||
if !strings.HasPrefix(data, "v2/") {
|
||||
data = "v2/" + data
|
||||
}
|
||||
log.Error("file upload", log.Any("url", statg.Conf.ProxyUrl.FileRes), log.Any("path", data))
|
||||
stdLog.ServerJSON(ctx, stdLog.Success, data)
|
||||
}
|
||||
return
|
||||
}
|
||||
Reference in New Issue
Block a user