springboot 下载文件
2018-09-04 09:49
519 查看
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.core.io.Resource; import org.springframework.core.io.ResourceLoader; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; import Java.nio.file.Paths; /** * 下载图片 * * @author zcqshine */ @RestController @RequestMapping("download") public class DownloadController { private final ResourceLoader resourceLoader; @Value("${upload.file.path}") private String filePath; @Autowired public DownloadController(ResourceLoader resourceLoader) { this.resourceLoader = resourceLoader; } @GetMapping(value = "/{filename:.+}") public ResponseEntity<?> getFile(@PathVariable String filename) { try { String path = Paths.get(filePath, filename).toString(); Resource resource = resourceLoader.getResource("file:" + path); return ResponseEntity.ok(resource); } catch (Exception e) { throw e; } } }
相关文章推荐
- SpringBoot下文件上传与下载的实现
- SpringBoot后台实现文件上传下载
- Spring Boot 微服务之间通过FeignClient进行大文件下载:
- SpringBoot文件上传下载
- 009 spring boot中文件的上传与下载
- spring-boot二进制文件下载
- SpringBoot下文件上传与下载的实现
- Spring Boot入门——文件上传与下载
- Spring Boot文件上传与下载
- springBoot通过表单的提交进行AmazonS3 进行文件的上传下载删除(不存储在本地)。
- SpringBoot文件上传下载和多文件上传(图文详解)
- Spring Boot + thymeleaf 实现文件上传下载功能
- SpringBoot下文件上传与下载的实现
- springboot 中文件上传下载实例代码
- springboot文件上传下载
- SpringBoot文件上传下载和多文件上传(图文详解)
- SpringBoot下文件上传与下载的实现
- SpringBoot 文件上传和下载的实现源码
- SpringBoot文件上传下载和多文件上传(图文详解)
- SpringBoot下文件上传与下载的实现