Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

387
Visualizações
How to download blobs from azure storage via node js to local storage?

I have followed official documentation for downloading blobs, but it downloads blob with metadata and properties. What I need to do is download blob file as it is from azure storage to local file system with node js. Please note that my blob storage is private.

Below is the code I have as of now

    const { BlobServiceClient } = require('@azure/storage-blob');
    const { v1: uuidv1} = require('uuid'); 
    async function main() {
        console.log('Azure Blob storage v12 - JavaScript quickstart sample');
        // Quick start code goes here
        const AZURE_STORAGE_CONNECTION_STRING = process.env.AZURE_STORAGE_CONNECTION_STRING;
        const containerName = process.env.CONTAINER_NAME;
    
        // Create the BlobServiceClient object which will be used to create a container client
        const blobServiceClient = BlobServiceClient.fromConnectionString(AZURE_STORAGE_CONNECTION_STRING);
        // Get a reference to a container
        const containerClient = blobServiceClient.getContainerClient(containerName);
        const blockBlobClient = containerClient.getBlockBlobClient(process.env.BLOB_NAME);
        const downloadBlockBlobResponse = await blockBlobClient.download(0);
        console.log('\nDownloaded blob content...');
        console.log('\t', await streamToString(downloadBlockBlobResponse.readableStreamBody));
    }
    async function streamToString(readableStream) {
        return new Promise((resolve, reject) => {
        const chunks = [];
        readableStream.on("data", (data) => {
        chunks.push(data.toString());
        });
        readableStream.on("end", () => {
        resolve(chunks.join(""));
        });
        readableStream.on("error", reject);
        });
   }
    main().then(() => console.log('Done')).catch((ex) => console.log(ex.message))
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

To save the blob content to your local file system, you can simply use downloadToFile method.

Essentially change the following line of code:

const downloadBlockBlobResponse = await blockBlobClient.download(0);

to

const downloadBlockBlobResponse = await blockBlobClient.downloadToFile('local-file-path');

You would also not need streamToString method so you can safely delete that.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda