-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
downloadBlockBlobResponse.readableStreamBody in node js not downloading the whole file #5260
Comments
Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @xgithubtriage |
1 similar comment
Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @xgithubtriage |
If anyone can help ASAP that will be great as I am blocked and see no other way out reading the limited documentation provided on your site |
@kriti218 // error handlers should also be added
const fileStream = fs.createWriteStream("/path/to/destination");
downloadBlockBlobResponse.readableStreamBody.pipe(fileStream); There is also the downloadToFile method to make downloading a blob to a file easier as long as the file doesn't already exist on your system. |
Thanks @chradek for unblocking me. Can i give "sas url to the blob file" in place of blob file path in "downloadToFile" method? |
@kriti218 you can create an instance of |
i did that but i am getting error "BlobClient is not a constructor". import * as Azure from "@azure/storage-blob"; var blobClient = new BlobClient('sas url of blob file'); |
@kriti218 To accomplish what you want to do with version 10.5 of the SDK, you can do something like the following: const { createWriteStream} = require('fs');
const { join } = require('path');
const { BlobURL, Aborter, StorageURL, AnonymousCredential } = require('@azure/storage-blob');
async function run() {
const blobUrl = new BlobURL(
'MY-SAS-CONNECTION-STRING',
StorageURL.newPipeline(new AnonymousCredential())
);
const blob = await blobUrl.download(Aborter.none, 0);
// does not check if file already exists on system
await downloadToFile(join(__dirname, 'test.txt'), blob);
}
function downloadToFile(path, blob) {
return new Promise((resolve, reject) => {
const fileStream = createWriteStream(path);
blob.readableStreamBody.on('error', reject);
fileStream.on('error', reject);
fileStream.on('close', resolve);
blob.readableStreamBody.pipe(fileStream);
});
}
run(); If you're interested in trying out the preview version of the SDK, you can install it by running Here's what the equivalent code looks like in the preview version of the SDK: const { join } = require('path');
const { BlobClient } = require('@azure/storage-blob');
async function run() {
const client = new BlobClient(
'MY-SAS-CONNECTION-STRING'
);
// Checks if file exists on system and throws error if it does
await client.downloadToFile(join(__dirname, 'test.txt'));
}
run(); |
The preview version looks far better but i have to deploy these changes in production so would not be willing to use "preview" version as that might break because of continuous changes. Thanks! One feedback, please improve the documentation by giving some examples as it is easy to understand. |
@XiaoningLiu can we consider closing this issue as we have provided guidance on the approach to take with V12 SDK for js |
Hi, in latest commits, we provided detialed samples and references for storage SDKs. Will close this issue. |
Describe the bug
i am following what is mentioned in "getting started" and code sample. My requirement is to download a zip file from blob to a predefined location and upload it in release pipeline of Azure devops task.
The issue is using this command
var data = downloadBlockBlobResponse.readableStreamBody;
fileSystem.writeFile(fileName, data);
is copying only 1kb data and exiting. Can you please let me know what is wrong here.
The text was updated successfully, but these errors were encountered: