This commit is contained in:
@@ -504,9 +504,7 @@ public class ApiController {
|
|||||||
errorData));
|
errorData));
|
||||||
}
|
}
|
||||||
|
|
||||||
Path filePath = Paths.get(entityResponse.getProtectedFilePath());
|
|
||||||
File file = cloudStorageService.readFileFromStorageByPath(entityResponse.getProtectedFilePath());
|
File file = cloudStorageService.readFileFromStorageByPath(entityResponse.getProtectedFilePath());
|
||||||
long fileSize = Files.size(filePath);
|
|
||||||
|
|
||||||
if (!file.exists()) {
|
if (!file.exists()) {
|
||||||
Map<String, Object> errorData = new HashMap<>();
|
Map<String, Object> errorData = new HashMap<>();
|
||||||
@@ -518,11 +516,8 @@ public class ApiController {
|
|||||||
errorData));
|
errorData));
|
||||||
}
|
}
|
||||||
|
|
||||||
String contentType = determineContentType(filePath);
|
|
||||||
|
|
||||||
return ResponseEntity.ok()
|
return ResponseEntity.ok()
|
||||||
.contentLength(fileSize)
|
.contentLength(file.length())
|
||||||
.contentType(MediaType.parseMediaType(contentType))
|
|
||||||
.header(HttpHeaders.CONTENT_DISPOSITION,
|
.header(HttpHeaders.CONTENT_DISPOSITION,
|
||||||
"attachment; filename=\"" + entityResponse.getFileName() + "\"")
|
"attachment; filename=\"" + entityResponse.getFileName() + "\"")
|
||||||
.body(file);
|
.body(file);
|
||||||
@@ -624,13 +619,4 @@ public class ApiController {
|
|||||||
|
|
||||||
return errorDetail;
|
return errorDetail;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private String determineContentType(Path filePath) throws IOException {
|
|
||||||
String contentType = Files.probeContentType(filePath);
|
|
||||||
if (contentType == null) {
|
|
||||||
contentType = "application/octet-stream";
|
|
||||||
}
|
|
||||||
return contentType;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -63,12 +63,6 @@ public class FileController {
|
|||||||
FileEntity fileEntity = fileRepository.findById(fileId)
|
FileEntity fileEntity = fileRepository.findById(fileId)
|
||||||
.orElseThrow(() -> new FileNotFoundException("Not found: " + fileId));
|
.orElseThrow(() -> new FileNotFoundException("Not found: " + fileId));
|
||||||
|
|
||||||
// Path filePath = Paths.get(fileEntity.getFilePath());
|
|
||||||
// if (!Files.exists(filePath)) {
|
|
||||||
// log.error("Not on disk: {}", fileEntity.getFilePath());
|
|
||||||
// return ResponseEntity.notFound().build();
|
|
||||||
// }
|
|
||||||
|
|
||||||
File file = cloudStorageService.readFileFromStorageByPath(fileEntity.getFilePath());
|
File file = cloudStorageService.readFileFromStorageByPath(fileEntity.getFilePath());
|
||||||
|
|
||||||
if (file == null || !file.exists()) {
|
if (file == null || !file.exists()) {
|
||||||
|
|||||||
Reference in New Issue
Block a user