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?
⚠Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
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.
Hi @willKim19,
Please see the example from @XiaoningLiu above. Let us know if you have any further questions.
Thanks,
~ Mark