我有以下代码可以将文件从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
到本地存储?
不可以。GoogleCloud Storage没有内置的目录概念。相反,只有对象名称包含“ /”字符。用户界面和命令行实用程序假装为方便起见而存在这样的概念,但是API没有真正的概念。相反,您将需要使用对象列表方法来遍历您感兴趣的对象,并单独进行调用以下载每个对象。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句