init: web_hgdjc_server
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
package uploadapi
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"videoweb/app/service/uploadser"
|
||||
"videoweb/pub/common"
|
||||
"videoweb/pub/common/log"
|
||||
"videoweb/pub/common/srvdef"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// UploadImage 上传图片
|
||||
// @Tags 上传
|
||||
// @Summary 图片上传
|
||||
// @Description 将图片转发至存储服务 /media/web/autopublish/image
|
||||
// @Accept multipart/form-data
|
||||
// @Produce json
|
||||
// @Param file formData file true "图片文件"
|
||||
// @Param watermark formData string false "是否加水印:1加,其他情况不加(头像不加)"
|
||||
// @Success 200 {object} uploadser.ImageUploadResp "成功"
|
||||
// @Failure 400 {string} string "参数错误"
|
||||
// @Router /api/app/upload/image [post]
|
||||
func UploadImage(ctx *gin.Context) {
|
||||
f, err := ctx.FormFile("file")
|
||||
if err != nil {
|
||||
common.ServerJSON(ctx, srvdef.ErrParamError, "file 不能为空")
|
||||
return
|
||||
}
|
||||
|
||||
watermark := int64(0)
|
||||
if ctx.PostForm("watermark") == "1" {
|
||||
watermark = 1
|
||||
}
|
||||
|
||||
param := &uploadser.ImageParam{
|
||||
FileHeader: f,
|
||||
Watermark: watermark,
|
||||
}
|
||||
respBytes, err := uploadser.ForwardImage(param)
|
||||
if err != nil {
|
||||
log.Error("UploadImage forward failed", log.E(err))
|
||||
common.ServerJSON(ctx, srvdef.ServerError, nil)
|
||||
return
|
||||
}
|
||||
|
||||
ctx.Data(http.StatusOK, "application/json; charset=utf-8", respBytes)
|
||||
}
|
||||
Reference in New Issue
Block a user