Initial commit: web_hghl_server
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,86 @@
|
||||
package web_file
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"videoweb/pub/common"
|
||||
"videoweb/pub/common/log"
|
||||
"videoweb/pub/common/srvdef"
|
||||
"videoweb/pub/storage"
|
||||
"videoweb/pub/storage/proxy"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// @Tags 文件上传
|
||||
// @Summary 图片上传
|
||||
// @Description 图片上传
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param file formData file true "文件"
|
||||
// @Success 200 {object}} UploadImageResp "成功"
|
||||
// @Failure 400 {string} string "失败"
|
||||
// @Router /api/web/file/uploadImg [POST]
|
||||
func UploadImage(ctx *gin.Context) {
|
||||
f, err := ctx.FormFile("file")
|
||||
if err != nil {
|
||||
common.ServerJSON(ctx, srvdef.ErrParamError, err.Error())
|
||||
return
|
||||
}
|
||||
imageUpoadDomain := proxy.BucketImageAddressV2
|
||||
p, err := storage.UploadImage(ctx, f, imageUpoadDomain)
|
||||
if err != nil {
|
||||
common.ServerJSON(ctx, srvdef.ServerError, err.Error())
|
||||
return
|
||||
}
|
||||
resp := &UploadImageResp{Path: p}
|
||||
common.ServerJSON(ctx, srvdef.Success, resp)
|
||||
}
|
||||
|
||||
// @Tags 文件上传
|
||||
// @Summary 图片批量上传
|
||||
// @Description 图片批量上传
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param file[] formData file true "文件"
|
||||
// @Success 200 {object}} UploadImagesResp "成功"
|
||||
// @Failure 400 {string} string "失败"
|
||||
// @Router /api/web/file/uploadImgs [POST]
|
||||
func UploadImages(ctx *gin.Context) {
|
||||
form, err := ctx.MultipartForm()
|
||||
if err != nil {
|
||||
common.ServerJSON(ctx, srvdef.ErrParamError, err.Error())
|
||||
return
|
||||
}
|
||||
resp := &UploadImagesResp{
|
||||
Paths: make([]string, 0),
|
||||
}
|
||||
domain := proxy.BucketImageAddressV2
|
||||
|
||||
files := form.File["file[]"]
|
||||
for _, f := range files {
|
||||
fi, err := f.Open()
|
||||
defer func() {
|
||||
_ = fi.Close()
|
||||
}()
|
||||
if err != nil {
|
||||
log.Warn("headers Open file wrong ", log.Any("Error", err))
|
||||
common.ServerJSON(ctx, srvdef.ErrParamError, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
byteData, err := ioutil.ReadAll(fi)
|
||||
if err != nil {
|
||||
log.Warn("request multipart wrong ", log.Any("Error", err))
|
||||
common.ServerJSON(ctx, srvdef.ErrParamError, err.Error())
|
||||
return
|
||||
}
|
||||
path, err := proxy.UploadImg(f.Filename, byteData, domain)
|
||||
if err != nil {
|
||||
log.Warn("request multipart wrong ", log.Any("Error", err))
|
||||
common.ServerJSON(ctx, srvdef.UploadToFileSrvFailed, err.Error())
|
||||
return
|
||||
}
|
||||
resp.Paths = append(resp.Paths, path)
|
||||
}
|
||||
common.ServerJSON(ctx, srvdef.Success, resp)
|
||||
}
|
||||
Reference in New Issue
Block a user