如何在java中从azure存储下载目录和压缩文件夹
我已经尝试过这样的尝试。我无法下载
CloudStorageAccount account = CloudStorageAccount.parse("connection string");
CloudBlobClient serviceClient = account.createCloudBlobClient();
CloudBlobContainer container = serviceClient.getContainerReference(containername);
for (com.microsoft.azure.storage.blob.ListBlobItem blobItem : container.listBlobs()) {
// If the item is a blob, a virtual directory.
if (blobItem instanceof CloudBlobDirectory) {
CloudBlobDirectory blobDir = (CloudBlobDirectory) blobItem;
downloadDirectory(blobDir);
}
}
public static void downloadDirectory(CloudBlobDirectory blobDir)
throws IOException, StorageException, URISyntaxException {
if (blobDir.getPrefix().equals(destFilePath)) {
for (ListBlobItem blobInDir : blobDir.listBlobs()) {
if (blobInDir instanceof CloudBlockBlob) {
ByteArrayOutputStream outputStream =new ByteArrayOutputStream();
((CloudBlockBlob) blobInDir).download(outputStream);
((CloudBlockBlob) blobInDir).downloadToFile(destFilePath);
CloudBlockBlob blob = (CloudBlockBlob) blobInDir;
blob.downloadToFile(destFilePath);
}
}
}
}
我尝试从Azure存储中下载文件夹,但我无法下载作为文件夹
I already tried like this. I cant able to download
CloudStorageAccount account = CloudStorageAccount.parse("connection string");
CloudBlobClient serviceClient = account.createCloudBlobClient();
CloudBlobContainer container = serviceClient.getContainerReference(containername);
for (com.microsoft.azure.storage.blob.ListBlobItem blobItem : container.listBlobs()) {
// If the item is a blob, a virtual directory.
if (blobItem instanceof CloudBlobDirectory) {
CloudBlobDirectory blobDir = (CloudBlobDirectory) blobItem;
downloadDirectory(blobDir);
}
}
public static void downloadDirectory(CloudBlobDirectory blobDir)
throws IOException, StorageException, URISyntaxException {
if (blobDir.getPrefix().equals(destFilePath)) {
for (ListBlobItem blobInDir : blobDir.listBlobs()) {
if (blobInDir instanceof CloudBlockBlob) {
ByteArrayOutputStream outputStream =new ByteArrayOutputStream();
((CloudBlockBlob) blobInDir).download(outputStream);
((CloudBlockBlob) blobInDir).downloadToFile(destFilePath);
CloudBlockBlob blob = (CloudBlockBlob) blobInDir;
blob.downloadToFile(destFilePath);
}
}
}
}
I tried to download a folder from azure storage, but I cant able to download as a folder
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用此 Java 代码从容器(Azure 存储帐户)下载该文件夹。由于我无法测试它,因此我的 IDE 存在问题。但你可以在你的环境中尝试一下。
参考:从 blob 存储下载虚拟目录
You can use this Java code to download the folder from Container(Azure Storage Account). Since i am not able to test it there is problem in my IDE. but you can try out in your environment.
Reference : download virtual directory from blob storage