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

425
Views
Cómo enviar la respuesta de Buffer de una API, como respuesta de otra API: NODE JS

Soy nuevo en node.js y desarrollo backend. Tengo un problema al devolver la respuesta del búfer. ¿Alguien puede ayudarme con el siguiente escenario?

Tengo una función de API de back-end en la que estoy obteniendo varias imágenes del almacenamiento en la nube, que devuelve varios archivos de búfer como respuesta.

Ahora que las respuestas del búfer estoy pasando nuevamente a una función API de terceros...

esa función API de terceros procesará todos los archivos de búfer y generará un solo búfer de imagen.

este último búfer de imagen única debería ser mi respuesta de la API al front-end.

pero de alguna manera no puedo enviar ese búfer tal como está, se está cambiando.

y en el front-end cuando estoy tratando de hacer response.blob(); su error de generación

No capturado (en promesa) TypeError: no se pudo ejecutar 'blob' en 'Respuesta': flujo de cuerpo ya leído ¿Alguien puede tener alguna idea de cómo enviar la respuesta del búfer correctamente?

//a continuación hay un código para el backend

 downloadSingle = aysnc(req, res){ try{ //I am fetching files from cloud storage let filelist = [] //I will have a multiple file name in file list; let OutputBuffers = []; for (let i =0; i<filelist.length; i++){ const sFiles = await // code for fetching files from cloud storage.. its working fine const sFileBuffer = await streamToBuffer(sFiles.Body) OutputBuffers.push({'bufferName': 'fileList[i]' , 'buffer': sFileBuffer}) } if(OutputBuffers.length>0){ const formData = new FormData(); OutputBuffers.forEach(f=>{ formData.append('files', Buffer.form(f.buffer), {fileName: f.bufferName})) } try{ //here I am hitting another API to get a single file from Multiple buffer files // this API returns buffer response in body and header info //I need to pass this response buffer and header as it is to front end as response const result = await fetch(`ThirdParty_API_URL`, {method: "POST", body: formData}); return res.send(result); //I think here I am making mistake } catch(e){ return res.status(500).json({'error': e}) } } } catch(e){ return res.status(500).json({'error': e}) } }

// código para la interfaz

 const handleDownloadEvent = async(){ const response = await fetch(`API_URL_for_downloadSingle`, {method: "GET"}); if(response.ok){ const fileName = response.headers.get("Content-Disposition"); const blob = await response.blob(); // this is throwing error //Uncaught (in promise) TypeError: Failed to execute 'blob' on 'Response': body stream already read const url = URL.createObjectURL(blob) } }
about 4 years ago · Juan Pablo Isaza
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!