🐛 本地存储, 获取文件不存在返回状态码 404

This commit is contained in:
zhaojun1998
2020-01-07 22:57:59 +08:00
parent 5495abc881
commit 7c729a72e2

View File

@@ -32,7 +32,7 @@ public class LocalController {
public ResponseEntity<FileSystemResource> downAttachment(final HttpServletRequest request) {
String path = (String) request.getAttribute(
HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE);
String bestMatchPattern = (String ) request.getAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE);
String bestMatchPattern = (String) request.getAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE);
AntPathMatcher apm = new AntPathMatcher();
String filePath = apm.extractPathWithinPattern(bestMatchPattern, path);
@@ -41,6 +41,11 @@ public class LocalController {
private ResponseEntity<FileSystemResource> export(File file) {
if (!file.exists()) {
return ResponseEntity.notFound().build();
}
MediaType mediaType = MediaType.APPLICATION_OCTET_STREAM;
HttpHeaders headers = new HttpHeaders();