|
- package hdl
-
- import (
- "applet/app/db"
- "applet/app/e"
- "applet/app/lib/validate"
- "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 = validate.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/admin/file/upload/callback"
- res, err := svc.ImgReqUpload(c, "", 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)
- masterListCfgDb := db.MasterListCfgDb{}
- masterListCfgDb.Set()
- fileBucketRegion := masterListCfgDb.MasterListCfgGetOneData("0", "file_bucket_region")
- if err != nil {
- e.OutErr(c, e.ERR_BAD_REQUEST, err)
- return
- }
- my1["host"] = fileBucketRegion
- e.OutSuc(c, my1, nil)
-
- }
|