如何从谷歌存储下载文件夹

埃拉德·本达(Elad Benda)

我有以下代码可以将文件从Google存储空间下载到本地存储空间:

@Override
public void downloadFile(URI originFileLocation, URI destinationFileLocation) throws IOException {
    StorageFileId gcsFileId = fileIdCreator.createFromUri(originFileLocation);
    Get getRequest = gsClient.objects().get(gcsFileId.getBucket(), gcsFileId.getObjectId());
    File localFile = new File(destinationFileLocation);
    if (!localFile.exists())
    {
        localFile.createNewFile();
    }
    try (FileOutputStream fileOutputStream = new FileOutputStream(localFile))
    {
        getRequest.getMediaHttpDownloader().setDirectDownloadEnabled(false);
        getRequest.executeMediaAndDownloadTo(fileOutputStream);
    }       
}

是否有API可以将A下载directory and all its subDirectories到本地存储?

布兰登·雅伯(Brandon Yarbrough)

否。GoogleCloud Storage没有内置的目录概念。相反,只有对象名称包含“ /”字符。用户界面和命令行实用程序假装为方便起见而存在这些概念,但是API没有真正的概念。相反,您将需要使用对象列表方法来遍历您感兴趣的对象,并单独进行调用以下载每个对象。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章