Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

203
Views
Cómo descargar un archivo png del almacenamiento de blob azul de contenido stringstream usando javascript

He escrito este código para obtener datos y recibo una respuesta como esta

 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); }); } if (type == "download") { const name = req.query.name || req.body.name; const itemname = req.query.itemname || req.body.itemname; var container = name ? name : "securesharecc"; const containerClient = await blobServiceClient.getContainerClient(container); const blobName = itemname ? itemname : "sample.png"; const blockBlobClient = containerClient.getBlockBlobClient(blobName); const downloadBlockBlobResponse = await blockBlobClient.download(0); console.log("\nDownloaded blob content..."); var base64string = await streamToString(downloadBlockBlobResponse.readableStreamBody); console.log("\t", base64string); context.res = { body: { data: base64string } }; context.done(); }

entonces este código muestra una cadena de un archivo que usa el nombre del elemento en un contenedor de Azure.

Pero recibo respuestas como esta.

 { "data": "PNG\r\n\u001a\n\u0000\u0000\u0000\rIHDR\u0000\u0000\u0002�\u0000\u0000\u0001�\b\u0002\u0000\u0000\u0000\u000f�\u001fl\u0000\u0000\u0000\u0001sRGB\u0000��\u001c�\u0000\u0000\u0000\u0004gAMA\u0000\u0000��\u000b ....." }

¿Qué codificar si quiero descargar directamente este archivo en lugar de mostrar el contenido? ¿Cómo hacerlo?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Intente cambiar su método streamToString a algo como:

 async function streamToString(readableStream) { return new Promise((resolve, reject) => { let chunks = Buffer.from([]); readableStream.on("data", (data) => { chunks = Buffer.concat([chunks, data], chunks.length + data.length); }); readableStream.on("end", () => { resolve(chunks); }); readableStream.on("error", reject); }); }

Esencialmente, los archivos de imagen son archivos binarios y no debe intentar convertir sus datos en cadenas.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!