0
votes

I am very new to java script. I want to download a blob file from the azure blob storage. I have the sas token and complete url to the individual block blob The url looks like this: https://xxxxxxxxxx.blob.core.windows.net/ABC/ABC/20216063/cvf.gbl

In online i have come across download methods which require container name and blob name. I dont know the container name and blob name. i have the url to the individual blob file.

How to download the blob using only sas token and the blob url using java script?

1

1 Answers

2
votes

You could create an HTTP GET request and pipe its response into a writable file stream. With the below code you could download the file if you don't the blob name.

    const sasurl="your sas url";
    const https = require('https');
    const url = require('url');;
    const path = require('path');
    const fs = require('fs');
    const filename=url.parse(sasurl).pathname.split('/').pop();
    const file = fs.createWriteStream(filename);
    const request = https.get(sasurl, function(response) {
    response.pipe(file);
    });