forked from all_user/stat_center
38 lines
810 B
Go
38 lines
810 B
Go
package fileApi
|
|
|
|
import (
|
|
"stat/common/file"
|
|
"stat/common/stdLog"
|
|
"stat/statg"
|
|
|
|
"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())
|
|
}
|
|
stdLog.ServerJSON(ctx, stdLog.Success, data)
|
|
|
|
return
|
|
}
|