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

373
Views
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 answers
Answer question

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