如何从 google 存储下载文件夹
how to download a folder from google storage
我有这段代码可以将文件从 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 将 directory and all its subDirectories
下载到本地存储?
没有。 Google Cloud Storage 没有内置的目录概念。相反,只有包含“/”字符的对象名称。为了方便起见,用户界面和命令行实用程序假装存在这些概念,但 API 没有它们的真实概念。相反,您需要使用对象列表方法来遍历您感兴趣的对象并单独调用以下载每个对象。
我有这段代码可以将文件从 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 将 directory and all its subDirectories
下载到本地存储?
没有。 Google Cloud Storage 没有内置的目录概念。相反,只有包含“/”字符的对象名称。为了方便起见,用户界面和命令行实用程序假装存在这些概念,但 API 没有它们的真实概念。相反,您需要使用对象列表方法来遍历您感兴趣的对象并单独调用以下载每个对象。