upload.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /*
  2. * @desc:上传适配器
  3. * @company:云南省奇讯科技有限公司
  4. * @Author: yixiaohu
  5. * @Date: 2021/7/7 8:54
  6. */
  7. package adapter
  8. import (
  9. "github.com/gogf/gf/frame/g"
  10. "github.com/gogf/gf/net/ghttp"
  11. )
  12. // FileInfo 上传的文件信息
  13. type FileInfo struct {
  14. FileName string `json:"fileName"`
  15. FileSize int64 `json:"fileSize"`
  16. FileUrl string `json:"fileUrl"`
  17. FileType string `json:"fileType"`
  18. }
  19. type UploadAdapter interface {
  20. UpImg(file *ghttp.UploadFile) (fileInfo *FileInfo, err error)
  21. UpFile(file *ghttp.UploadFile) (fileInfo *FileInfo, err error)
  22. UpImgs(files []*ghttp.UploadFile) (fileInfos []*FileInfo, err error)
  23. UpFiles(files []*ghttp.UploadFile) (fileInfos []*FileInfo, err error)
  24. }
  25. type upload struct {
  26. adapter UploadAdapter
  27. }
  28. var (
  29. upType = g.Cfg().GetString("upload.type")
  30. Upload *upload
  31. )
  32. func (u upload) UpImg(file *ghttp.UploadFile) (fileInfo *FileInfo, err error) {
  33. return u.adapter.UpImg(file)
  34. }
  35. func (u upload) UpFile(file *ghttp.UploadFile) (fileInfo *FileInfo, err error) {
  36. return u.adapter.UpFile(file)
  37. }
  38. func (u upload) UpImgs(files []*ghttp.UploadFile) (fileInfos []*FileInfo, err error) {
  39. return u.adapter.UpImgs(files)
  40. }
  41. func (u upload) UpFiles(files []*ghttp.UploadFile) (fileInfos []*FileInfo, err error) {
  42. return u.adapter.UpFiles(files)
  43. }