|
- package hdl
-
- import (
- "applet/app/db"
- "applet/app/e"
- "applet/app/enum"
- "applet/app/svc"
- "applet/app/utils"
- "github.com/gin-gonic/gin"
- "github.com/mcuadros/go-defaults"
- )
-
- func ImgReqUpload(c *gin.Context) {
- var args struct {
- DirName string `json:"dir_name,omitempty" default:"0"`
- FileName string `json:"file_name" binding:"required" label:"文件名"`
- FileSize int64 `json:"file_size" binding:"gt=1" label:"文件大小"` // 文件大小, 单位byte
- }
- defaults.SetDefaults(&args)
- err := c.ShouldBindJSON(&args)
- if err != nil {
- err = svc.HandleValidateErr(err)
- err1 := err.(e.E)
- e.OutErr(c, err1.Code, err1.Error())
- return
- }
-
- scheme := "http"
- if c.Request.TLS != nil {
- scheme = "https"
- }
- // 拼装回调地址
- callbackUrl := scheme + "://" + c.Request.Host + "/api/file/upload/callback"
- if true { // 本地使用内网穿透地址测试
- callbackUrl = ""
- }
- res, err := svc.ImgReqUpload("", args.DirName, args.FileName, callbackUrl, args.FileSize)
- if err != nil {
- e.OutErr(c, e.ERR_BAD_REQUEST, err.Error())
- return
- }
- my := utils.SerializeStr(res)
- var my1 map[string]interface{}
- utils.Unserialize([]byte(my), &my1)
- sysCfgDb := db.SysCfgDb{}
- sysCfgDb.Set()
- my1["host"] = sysCfgDb.SysCfgGetWithDb(enum.FileBucketRegion)
- e.OutSuc(c, my1, nil)
-
- }
|