Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

137
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda