file.go 860 B

123456789101112131415161718192021222324252627282930313233343536
  1. package http
  2. import (
  3. "bytes"
  4. "io"
  5. "go-common/app/admin/main/upload/model"
  6. "go-common/library/ecode"
  7. "go-common/library/log"
  8. bm "go-common/library/net/http/blademaster"
  9. "go-common/library/net/http/blademaster/binding"
  10. )
  11. // InternalUploadAdminImage .
  12. func InternalUploadAdminImage(c *bm.Context) {
  13. var err error
  14. up := new(model.UploadParam)
  15. if err = c.BindWith(up, binding.FormMultipart); err != nil {
  16. c.JSON(nil, ecode.RequestErr)
  17. return
  18. }
  19. up.WMInit()
  20. file, _, err := c.Request.FormFile("file")
  21. if err != nil {
  22. log.Error("upload.UploadImage.file.illegal,err::%v", err.Error())
  23. c.JSON(nil, ecode.RequestErr)
  24. return
  25. }
  26. defer file.Close()
  27. buf := new(bytes.Buffer)
  28. if _, err = io.Copy(buf, file); err != nil {
  29. c.JSON(nil, ecode.RequestErr)
  30. return
  31. }
  32. c.JSON(uaSvc.UploadAdminRecord(c, "internal_admin_upload", up, buf.Bytes()))
  33. }