finclip-app-manager/application/file.go

38 lines
1.1 KiB
Go
Raw Normal View History

2023-10-31 14:07:26 +08:00
package application
import (
"finclip-app-manager/domain/entity"
"finclip-app-manager/infrastructure/config"
"finclip-app-manager/infrastructure/utility"
"net/http"
"time"
"github.com/gin-gonic/gin"
"gitlab.finogeeks.club/finclip-backend-v2/finclip-mgo/bson"
"gitlab.finogeeks.club/finclip-backend/apm"
)
func UploadFile(c *gin.Context) {
traceCtx := apm.ApmClient().TraceContextFromGin(c)
inFile, fileHeader, err := c.Request.FormFile("file")
if err != nil {
log.Errorf("get form file err:", err.Error())
utility.MakeLocRsp(c, http.StatusBadRequest, utility.FS_BAD_JSON, gin.H{})
return
}
url, err := hCaller.Upload(traceCtx, fileHeader.Filename, inFile, config.Cfg.OpenCdn)
if err != nil {
log.Errorf("Upload err:", err.Error())
utility.MakeErrRsp(c, http.StatusInternalServerError, utility.FS_SYSTEM_CALL, err.Error(), gin.H{})
return
}
file := entity.File{
FileID: bson.NewObjectId().Hex(),
Name: fileHeader.Filename,
UploadDate: time.Now().UnixNano() / 1000000,
Size: fileHeader.Size,
Url: url,
}
c.JSON(http.StatusOK, file)
}