bfs.go 577 B

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