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

364
Vistas
Unable to Download all the Blobs in a container from Azure IOT Hub and getting error: Cannot read property 'on' of undefined

I have been trying to download 5 files uploaded as blobs already in azure cloud in container: updateappnew via a nodejs script. However I am getting error as in the image Cannot read property 'on' of undefined after the first blob of the five gets downloaded. I am sharing my code here and have been hoping to find on where the issue is actually happening and how can it be modified to download all the blobs one after other.

const { BlobServiceClient } = require('@azure/storage-blob');

// A helper function used to read a Node.js readable stream into a string

  return new Promise((resolve, reject) => {
    const chunks = [];
    readableStream.on("data", (data) => {
      chunks.push(data.toString());
    });
    readableStream.on("end", () => {
      resolve(chunks.join(""));
    });
    readableStream.on("error", reject);
  });
}
async function main() {
    const AZURE_STORAGE_CONNECTION_STRING = process.env.AZURE_STORAGE_CONNECTION_STRING;
    console.log('Azure Blob storage v12 - JavaScript quickstart sample'); ```
    // Quick start code goes here


// Create the BlobServiceClient object which will be used to create a container client
```const blobServiceClient = BlobServiceClient.fromConnectionString(AZURE_STORAGE_CONNECTION_STRING);```

// Create a unique name for the container
```const containerName = 'updateappnew';

console.log('\nFinding Container for updating file...');
console.log('\t', containerName);```


// Get a reference to a container
```const containerClient = blobServiceClient.getContainerClient(containerName);

console.log('\nListing blobs...');```




// List the blob(s) in the container.
```for await (const blob of containerClient.listBlobsFlat()) {
    console.log('\t', blob.name);
    const blockBlobClient = containerClient.getBlockBlobClient(blob.name);


}```


// List blobs
  ```i = 1;
  for await (const blob of containerClient.listBlobsFlat()) {
    console.log(`Blob ${i++}: ${blob.name}`);
const blockBlobClient = containerClient.getBlockBlobClient(blob.name);


const downloadBlockBlobResponse = await blockBlobClient.downloadToFile(`/home/administrator/file_${i-1}`);
    console.log('\nDownloaded blob content...');
    console.log('\t', await streamToString(downloadBlockBlobResponse.readableStreamBody));


   

  }


// In Node.js, get downloaded data by accessing downloadBlockBlobResponse.readableStreamBody // In browsers, get downloaded data by accessing downloadBlockBlobResponse.blobBody

}

main().then(() => console.log('Done')).catch((ex) => console.log(ex.message));

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

This error usually occurs when the accessed value does not exists. make sure to check the value within its condition.

Below is the sample code to download blobs:

const downloadResponse = await blockBlobURL.download(aborter, 0);
const downloadedContent = await streamToString(downloadResponse.readableStreamBody);
console.log(`Downloaded blob content: "${downloadedContent}"`);
 

Also we have a blog in GIT where we have the complete project with steps

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