Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

427
Vistas
How to send Buffer response of an API, as response of another API: NODE JS

I am new to node.js and backend development. I am facing a issue while returning buffer response. Can anyone help me with below scenario.

I am having backend API function in that, I am fetching multiple images from cloud storage, that returns multiple buffer files as response.

Now that buffer responses I am again passing to a third party API function...

that third party API function will process all buffer files and will generate a single image buffer.

this final single image buffer should be my response of API to front end.

but some how I am not able send that buffer as it is, its getting changed.

and on front end when I am trying to do response.blob(); its generating error

Uncaught (in promise) TypeError: Failed to execute 'blob' on 'Response': body stream already read Can anyone is having any idea how to send buffer response correctly.

//below is some code for 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})
   }
}

//code for front end

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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda