Skip to content

Node js – Download files from Azure Storage to local File system.

Last updated on November 21, 2022

const azureStorage = require('azure-storage');
const path = require('path');

const azureStorageConfig = {
    accountName: "",
    accountKey: "",
    blobURL: "",
    containerName: ""
};

const downloadBlob = async (blobName, downloadFilePath) => {
    return new Promise((resolve, reject) => {
        const name = path.basename(blobName);
        const blobService = azureStorage.createBlobService(azureStorageConfig.accountName, azureStorageConfig.accountKey); 
        blobService.getBlobToLocalFile(azureStorageConfig.containerName, blobName, `${downloadFilePath}${name}`, function(error, serverBlob) {
            if (error) {
                reject(error);
            } else {
                resolve(downloadFilePath);
            }
        });
    });
};

downloadBlob('images/6350402094004393-11.jpeg','./downloads/');
0 0 votes
Article Rating
Subscribe
Notify of
guest

1 Comment
Most Voted
Newest Oldest
Inline Feedbacks
View all comments