智盟项目
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

hdl_file_upload.go 1.4 KiB

1 year ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. package hdl
  2. import (
  3. "applet/app/db"
  4. "applet/app/e"
  5. "applet/app/lib/validate"
  6. "applet/app/svc"
  7. "applet/app/utils"
  8. "github.com/gin-gonic/gin"
  9. "github.com/mcuadros/go-defaults"
  10. )
  11. func ImgReqUpload(c *gin.Context) {
  12. var args struct {
  13. DirName string `json:"dir_name,omitempty" default:"0"`
  14. FileName string `json:"file_name" binding:"required" label:"文件名"`
  15. FileSize int64 `json:"file_size" binding:"gt=1" label:"文件大小"` // 文件大小, 单位byte
  16. }
  17. defaults.SetDefaults(&args)
  18. err := c.ShouldBindJSON(&args)
  19. if err != nil {
  20. err = validate.HandleValidateErr(err)
  21. err1 := err.(e.E)
  22. e.OutErr(c, err1.Code, err1.Error())
  23. return
  24. }
  25. scheme := "http"
  26. if c.Request.TLS != nil {
  27. scheme = "https"
  28. }
  29. // 拼装回调地址
  30. callbackUrl := scheme + "://" + c.Request.Host + "/api/admin/file/upload/callback"
  31. res, err := svc.ImgReqUpload(c, "", args.DirName, args.FileName, callbackUrl, args.FileSize)
  32. if err != nil {
  33. e.OutErr(c, e.ERR_BAD_REQUEST, err.Error())
  34. return
  35. }
  36. my := utils.SerializeStr(res)
  37. var my1 map[string]interface{}
  38. utils.Unserialize([]byte(my), &my1)
  39. masterListCfgDb := db.MasterListCfgDb{}
  40. masterListCfgDb.Set()
  41. fileBucketRegion := masterListCfgDb.MasterListCfgGetOneData("0", "file_bucket_region")
  42. if err != nil {
  43. e.OutErr(c, e.ERR_BAD_REQUEST, err)
  44. return
  45. }
  46. my1["host"] = fileBucketRegion
  47. e.OutSuc(c, my1, nil)
  48. }