This commit is contained in:
@@ -524,19 +524,13 @@ public class ApiController {
|
|||||||
// errorData));
|
// errorData));
|
||||||
// }
|
// }
|
||||||
|
|
||||||
StreamingResponseBody responseBody = outputStream -> {
|
byte[] bytes = cloudStorageService.readFileFromStorageBytes(entityResponse.getProtectedFilePath());
|
||||||
try (InputStream stream = cloudStorageService.readFileFromStorage(entityResponse.getProtectedFilePath())) {
|
|
||||||
ByteStreams.copy(stream, outputStream);
|
|
||||||
} catch (NoSuchKeyException e) {
|
|
||||||
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "File not found");
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
return ResponseEntity.ok()
|
return ResponseEntity.ok()
|
||||||
.contentType(MediaType.APPLICATION_OCTET_STREAM)
|
.contentType(MediaType.APPLICATION_OCTET_STREAM)
|
||||||
.header(HttpHeaders.CONTENT_DISPOSITION,
|
.header(HttpHeaders.CONTENT_DISPOSITION,
|
||||||
"attachment; filename=\"" + entityResponse.getFileName() + "\"")
|
"attachment; filename=\"" + entityResponse.getFileName() + "\"")
|
||||||
.body(responseBody);
|
.body(bytes);
|
||||||
} catch (FileEntityNotFoundException e) {
|
} catch (FileEntityNotFoundException e) {
|
||||||
Map<String, Object> errorData = new HashMap<>();
|
Map<String, Object> errorData = new HashMap<>();
|
||||||
errorData.put("fileId", fileId);
|
errorData.put("fileId", fileId);
|
||||||
|
|||||||
Reference in New Issue
Block a user