LocalSysFileServiceImpl.java 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. package com.ruoyi.file.service;
  2. import org.springframework.beans.factory.annotation.Value;
  3. import org.springframework.context.annotation.Primary;
  4. import org.springframework.stereotype.Service;
  5. import org.springframework.web.multipart.MultipartFile;
  6. import com.ruoyi.file.utils.FileUploadUtils;
  7. /**
  8. * 本地文件存储
  9. *
  10. * @author ruoyi
  11. */
  12. @Primary
  13. @Service
  14. public class LocalSysFileServiceImpl implements ISysFileService
  15. {
  16. /**
  17. * 资源映射路径 前缀
  18. */
  19. @Value("${file.prefix}")
  20. public String localFilePrefix;
  21. /**
  22. * 域名或本机访问地址
  23. */
  24. @Value("${file.domain}")
  25. public String domain;
  26. /**
  27. * 上传文件存储在本地的根路径
  28. */
  29. @Value("${file.path}")
  30. private String localFilePath;
  31. /**
  32. * 本地文件上传接口
  33. *
  34. * @param file 上传的文件
  35. * @return 访问地址
  36. * @throws Exception
  37. */
  38. @Override
  39. public String uploadFile(MultipartFile file) throws Exception
  40. {
  41. String name = FileUploadUtils.upload(localFilePath, file);
  42. String url = domain + localFilePrefix + name;
  43. return url;
  44. }
  45. }