如何从Azure Blob获取所有文件并将它们压缩成Zip文件?

huangapple go评论93阅读模式
英文:

How to grab all files from Azure Blob and Zip them?

问题

I have an Azure Blob with multiple containers. Each container contains various folders, and each folder holds multiple files. My goal is to retrieve all the files and provide them as a compressed ZIP archive. Currently, I'm only capable of fetching one file at a time.

public void downloadAllFromBlob(String containerName){
    CloudBlobClient blobClient = this.storageAccount.createCloudBlobClient();
    try{
        CloudBlobContainer container = blobClient.getContainerReference(containerName);
        
        if(container.exists()){
             // I aim to gather all files in the container and compress them into a ZIP
            for(ListBlobItem blobItem: container.listBlobs()){
                   // I can only list/view the blobs, without accessing contents within
            }
         }

     }catch(){
     }
}
英文:

I have an Azure Blob with many containers. Each container has multiple folders - and each folder has a bunch of files in it. I want to be able to grab all of the files and return them zipped. I'm currently only able to get one file at a time...

public void downloadAllFromBlob(String containerName){
    CloudBlobClient blobClient = this.storageAccount.createCloudBlobClient();
    try{
        CloudBlobContainer container = blobClient.getContainerReference(containerName);
        
        if(container.exists()){
             // I want to grab all the files in the container and zip them
            for(ListBlobItem blobItem: container.listBlobs()){
                   // i'm only able to list/VIEW the blobs, and not go into one and get all the contents
            }
         }

     }catch(){
     }
}

答案1

得分: 2

抱歉,在Azure Blob Storage中,目前没有批量检索功能可用。您需要像您上面所示的那样逐个下载每个 Blob。您可以尝试并行检索 Blob 以加快速度。

英文:

Unfortunately there's no batch retrieve capability available in Azure Blob Storage. You need need to download each blob individually as you showed above. You can try to retrieve blobs in parallel to speed things up.

huangapple
  • 本文由 发表于 2020年8月12日 10:25:56
  • 转载请务必保留本文链接:https://go.coder-hub.com/63368867.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定