Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

132
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda