当文件大小增加时,从java下载GoogleDrive文件需要时间

rslzwgfq  于 2021-07-05  发布在  Java
关注(0)|答案(0)|浏览(140)

我想下载一个文件从谷歌驱动器使用驱动器api和谷歌驱动器api或配置没有问题。问题是,我已经在云示例上部署了这个应用程序,当我单击下载按钮时,开始下载需要更多的时间。好像是先下载到云示例,开始接收给我。如何避免这种等待时间?我没有写任何变量,因为下载大文件时会浪费内存。我正在使用以下代码。请帮帮我。

@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);
}

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题