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

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/');

I hope you like this Post, Please feel free to comment below, your suggestion and problems if you face - we are here to solve your problems.

DMCA.com Protection Status