Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

133
Views
How to wait for operation to complete in azure blob service

How to use async/await on blob service. I am trying download and zip folder and hence want to wait untill download completes, so that I can go ahead and zip that file.but due to async behaviour sometime function misbehaveing.

Latest code:

            const blobServiceClient = BlobServiceClient.fromConnectionString("connect string");
             
            const containerClient = blobServiceClient.getContainerClient(containerName);
            
            for await (const blob of containerClient.listBlobsFlat({ prefix: path })) {
              
           if (fs.existsSync(fileUploadPath)) {
            var sourceFilePath = fileUploadPath + '/' + project.id + '/' + blob.name;
            if (!fs.existsSync(sourceFilePath)) {
                fs.mkdir(require('path').dirname(sourceFilePath), { recursive: true }, async(err) => {
                    if (err) {
                        console.log("Failed to mkdir:" + err);
                    }
                    console.log(blob.name)
                  await containerClient.getBlobClient(blob.name).downloadToFile(sourceFilePath,0,undefined);
                 
                });
            }
        } else{
        console.log('downloads folder does not configures!')
    }

I have a couple of doubts here,

  1. How efficient is downloadToFile? can it download large sized blobs?
  2. only immediate blob is downloaded that too with incomplete data and blobs under subdirectory are not being downloaded.
  3. I thought , streaming data is efficient way to download blobs?is there any API to stream data to local, like we had one in old library (getBlobToStream)?
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Using the latest version of the Azure Storage Blob SDK, you could convert your existing code to something like that:

const { BlobServiceClient, StorageSharedKeyCredential } = require("@azure/storage-blob");

const account = "<account>";
const accountKey = "<accountkey>";

const sharedKeyCredential = new StorageSharedKeyCredential(account, accountKey);
const blobServiceClient = new BlobServiceClient(
  `https://${account}.blob.core.windows.net`,
  sharedKeyCredential
);

const containerName = '<container name>';
const path = '<prefix>';

async function download() {
  var containerClient = blobServiceClient.getContainerClient(containerName);
  for await (const blob of containerClient.listBlobsFlat({ prefix: path })) {
    await containerClient.getBlobClient(blob.name)
      .downloadToFile(`./${blob.name}`);
  }
}

download()
  .then(() => console.log('Done'))
  .catch((ex) => console.log(ex.message));
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!