I want to download a file from Google Drive using Drive API and there is no issue with Google Drive API or configuration. The problem is, I have deployed this application on cloud instance and when I click on the download button it takes more time to start the download. Seems it download into the cloud instance first and start receiving to me. How to avoid this waiting time ? I haven't write to any variables because it waste the memory when downloading large files. I'm using following code. Please help me.
@RequestMapping(value = "/directDownload", method=RequestMethod.GET)
public ResponseEntity<Resource> directDownload(Principal principal,@RequestParam("fileId") String fileId,
@RequestParam("fileName") String fileName)
throws IOException {
Drive driveService = GoogleDriveService.get(principal);
OutputStream outputStream = new ByteArrayOutputStream();
driveService.files().get(fileId)
.executeMediaAndDownloadTo(outputStream);
ByteArrayOutputStream bbe = (ByteArrayOutputStream) outputStream;
HttpHeaders responseHeaders = new HttpHeaders();
responseHeaders.add(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename="
+ fileName);
responseHeaders.add(HttpHeaders.CONTENT_TYPE, "application/octet-stream");
return new ResponseEntity(bbe.toByteArray(), responseHeaders, HttpStatus.OK);
}