attachmentuploadhandler.go 620 B

123456789101112131415161718192021222324
  1. package handler
  2. import (
  3. "net/http"
  4. "slow_wild_api/apps/internal/logic"
  5. "slow_wild_api/apps/internal/response"
  6. "slow_wild_api/apps/internal/svc"
  7. "github.com/zeromicro/go-zero/rest/httpx"
  8. )
  9. func attachmentUploadHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
  10. return func(w http.ResponseWriter, r *http.Request) {
  11. file, header, errFile := r.FormFile("file")
  12. if errFile != nil {
  13. httpx.ErrorCtx(r.Context(), w, errFile)
  14. return
  15. }
  16. defer file.Close()
  17. l := logic.NewAttachmentUploadLogic(r.Context(), svcCtx)
  18. resp, err := l.AttachmentUpload(file, header)
  19. response.Response(w, resp, err)
  20. }
  21. }