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

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

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 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