LocalSysFileServiceImpl.java 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. public String uploadFile(MultipartFile file) throws Exception
  39. {
  40. String name = FileUploadUtils.upload(localFilePath, file);
  41. String url = domain + localFilePrefix + name;
  42. return url;
  43. }
  44. }