面包店
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.3 KiB

9 maanden geleden
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. package hdl
  2. import (
  3. "applet/app/db"
  4. "applet/app/e"
  5. "applet/app/enum"
  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 = svc.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/file/upload/callback"
  31. if true { // 本地使用内网穿透地址测试
  32. callbackUrl = ""
  33. }
  34. res, err := svc.ImgReqUpload("", args.DirName, args.FileName, callbackUrl, args.FileSize)
  35. if err != nil {
  36. e.OutErr(c, e.ERR_BAD_REQUEST, err.Error())
  37. return
  38. }
  39. my := utils.SerializeStr(res)
  40. var my1 map[string]interface{}
  41. utils.Unserialize([]byte(my), &my1)
  42. sysCfgDb := db.SysCfgDb{}
  43. sysCfgDb.Set()
  44. my1["host"] = sysCfgDb.SysCfgGetWithDb(enum.FileBucketRegion)
  45. e.OutSuc(c, my1, nil)
  46. }