| | |
| | | import com.ruoyi.system.mapper.UserFileMapper; |
| | | import com.ruoyi.system.model.UserFile; |
| | | import com.ruoyi.system.service.UserFileService; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.core.io.InputStreamResource; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.io.IOException; |
| | | import java.nio.file.Files; |
| | | import java.nio.file.Path; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | @Service |
| | | public class UserFileServiceImpl extends ServiceImpl<UserFileMapper, UserFile> implements UserFileService { |
| | | |
| | | @Value("${file.upload.dirFile}") |
| | | private Path fileLocation; |
| | | |
| | | @Override |
| | | |
| | | public InputStreamResource resolveResource(UserFile userFile){ |
| | | try { |
| | | var filePath = fileLocation.resolve(userFile.getName() + "." + userFile.getExtension()).normalize(); |
| | | if (!Files.exists(filePath)) { |
| | | return null; |
| | | } |
| | | return new InputStreamResource(Files.newInputStream(filePath)); |
| | | |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | } |
| | | return null; |
| | | |
| | | } |
| | | } |