我有这段代码可以将文件从谷歌存储下载到本地存储:
@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 可以将 目录及其所有子目录
下载到本地存储?
最佳答案
没有。 Google Cloud Storage 没有内置的目录概念。相反,只有包含“/”字符的对象名称。为了方便起见,用户界面和命令行实用程序假装存在这些概念,但 API 没有它们的真实概念。相反,您需要使用对象列表方法来遍历您感兴趣的对象,并单独调用以下载每个对象。
关于java - 如何从谷歌存储下载文件夹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39318138/