upload.go 580 B

12345678910111213141516171819202122232425
  1. package service
  2. import (
  3. "bytes"
  4. "context"
  5. "time"
  6. "go-common/app/admin/main/up/conf"
  7. "go-common/app/admin/main/up/dao"
  8. "go-common/library/ecode"
  9. "go-common/library/log"
  10. )
  11. // Upload upload.
  12. func (s *Service) Upload(c context.Context, fileName, fileType string, t time.Time, body []byte, bfs *conf.Bfs) (location string, err error) {
  13. if len(body) > bfs.MaxFileSize {
  14. err = ecode.FileTooLarge
  15. return
  16. }
  17. if location, err = dao.Upload(c, fileName, fileType, t.Unix(), bytes.NewReader(body), bfs); err != nil {
  18. log.Error("Upload error(%v)", err)
  19. return
  20. }
  21. return
  22. }