附近小店
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.
 
 
 

46 lines
1.4 KiB

  1. package hdl
  2. import (
  3. "applet/app/cfg"
  4. "applet/app/e"
  5. "applet/app/svc"
  6. "applet/app/utils"
  7. "fmt"
  8. "github.com/gin-gonic/gin"
  9. "net/http"
  10. "strings"
  11. )
  12. // ServiceFileUpload 上传文件
  13. // @Summary 基本配置-上传文件
  14. // @Tags 基本配置
  15. // @Description 基本配置-上传文件
  16. // @Accept json
  17. // @Produce json
  18. // @Param req body true "请求参数 表单提交 file文件流 type类型 微信p12文件-wechat_apiclient_cert 支付宝应用公钥证书 payAliNewAppCertSn 支付宝公钥证书 payAliNewAlipayrsaPublicKey 支付宝根证书 payAliNewAlipayRootCertSn"
  19. // @Success 200 {string} ""
  20. // @Failure 400 {object} md.Response "具体错误"
  21. // @Router /api/v1/communityTeam/agent/service/file/upload [POST]
  22. func ServiceFileUpload(c *gin.Context) {
  23. // 单文件上传
  24. file, err := c.FormFile("file")
  25. if err != nil {
  26. c.String(http.StatusBadRequest, fmt.Sprintf("upload error: %s", err.Error()))
  27. return
  28. }
  29. user := svc.GetUser(c)
  30. ext := strings.Split(file.Filename, ".")
  31. newName := c.GetString("mid") + "_" + utils.IntToStr(user.Info.Uid) + "_" + c.PostForm("type") + "." + ext[1]
  32. path := "./static/"
  33. if cfg.Prd {
  34. path = "/etc/zyos-admin/wx_check_file/"
  35. }
  36. if err := c.SaveUploadedFile(file, path+newName); err != nil {
  37. e.OutErr(c, 400, err.Error())
  38. return
  39. }
  40. e.OutSuc(c, "success", nil)
  41. return
  42. }