Azure-docs: Documentation does not detail how to actually download blobs realistically

Created on 2 Apr 2019  Â·  9Comments  Â·  Source: MicrosoftDocs/azure-docs

This snippet is "How to download blobs"

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

But reading the blob requires the content.length, a variable defined within the scope. This isn't a realistic use-case, how can I get the length of the blob if I don't know it beforehand?


Document Details

⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

Pri2 assigned-to-author blobsubsvc product-question storagsvc triaged

All 9 comments

There are methods to get the blob length which could be a workaround to get it prior to reading the blob, public long GetBlockBlobSize(string containerName, string blobName) { try { CloudBlobContainer container = _blobClient.GetContainerReference(containerName); var blockBlob = container.GetBlockBlobReference(blobName); blockBlob.FetchAttributes(); return blockBlob.Properties.Length; } catch (Exception ex) { throw; } }

This post was taken from https://stackoverflow.com/questions/47453990/c-sharp-azure-blob-storage-get-blob-size
Does this work for you ?

Thanks,
Adam

@willKim19 was the above response helpful to you ?

Thanks,
Adam

It was helpful, I think it would be useful to update the documentation with that snippet as well. Thank you

Thanks @willKim19 I'll assign to the author as doc-enhancement

@Adam-Smith-MSFT The SO question is regarded to C#. I couldn't find a similar method for nodejs v10SDK. Please advise.
Thanks

This was opened April 2 and we still have no answer. This SDK is unusable as there is no clear way how to get content size and download blob, neither it is clear how to list blobs in folders. I just had to create C# Azure functions to do the job and call those from node.js application. Is this experience node.js developers should have?

The questions is how to read data from a Node.js ReadableStream. Please refer to https://nodejs.org/api/stream.html#stream_readable_streams

Just like any Node.js readable stream, we don't need to know the content length to read blob data. For example, when reading from local file.

const readableStream = fs.createReadStream(pathToLocalFile);
readableStream.on("data", (data) => {
  // deal with incoming data here
});

You can do the same thing to the downloadResponse.readableStreamBody. Such as piping the stream directly to another writeable stream.

reassign: @mhopkins-msft

Hi @willKim19,

Please see the example from @XiaoningLiu above. Let us know if you have any further questions.

Thanks,
~ Mark

please-close

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Ponant picture Ponant  Â·  3Comments

bdcoder2 picture bdcoder2  Â·  3Comments

AronT-TLV picture AronT-TLV  Â·  3Comments

paulmarshall picture paulmarshall  Â·  3Comments

spottedmahn picture spottedmahn  Â·  3Comments