Created
July 20, 2020 23:22
-
-
Save Ikhiloya/5eb82e289b138469a05146698b23a289 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Override | |
public ResponseEntity<Object> downloadFile(String fileName, HttpServletRequest request) throws Exception { | |
Storage storage = storageOptions.getService(); | |
Blob blob = storage.get(BlobId.of(bucketName, fileName)); | |
ReadChannel reader = blob.reader(); | |
InputStream inputStream = Channels.newInputStream(reader); | |
byte[] content = null; | |
log.info("File downloaded successfully."); | |
content = IOUtils.toByteArray(inputStream); | |
final ByteArrayResource byteArrayResource = new ByteArrayResource(content); | |
return ResponseEntity | |
.ok() | |
.contentLength(content.length) | |
.header("Content-type", "application/octet-stream") | |
.header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + fileName + "\"") | |
.body(byteArrayResource); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment