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

312
Vistas
how to download files from ajax response if sent as blob?

I'm trying to make a web form to upload files to a server that processes them then returns them back to me to download.

I use the library Dropzone for a drag and drop UI, which uses ajax for that, so, my goal here is to download the files from inside the ajax success function.

The server sends the response as blob ? It looks like this:

{
  //...
  xhr: {
    //...
    status: 200,
    response: "����\u0000\u0010JFIF\u0000\u0001\u0001\u0000\u0000\u0001....",
    responseText: "����\u0000\u0010JFIF\u0000\u0001\u0001\u0000\u0000\u0001....",
    //...
  }
}

And the HTTP response headers are:

Content-Disposition: attachment; filename="photo.jpg"
Content-Type: image/jpeg

How can I download those files correctly?

After the files downloads they don't open, for instance, a jpg file gives me this error when I open it:

Error interpreting JPEG image file (Not a JPEG file: starts with 0xef 0xbf)

I tried to download them as file and also tried to convert them to blob following the answers on the question, but, I can't figure out what I'm doing wrong.

//this fails:
let file = new File([xhr.response], 'photo-processed.jpg', {type: 'image/jpeg'});
saveAs(file);

//this fails too:
let blob = new Blob([xhr.response], {type: 'image/jpeg'});
saveAs(blob, 'photo-processed.jpg');

//adding this didn't work either:
let downloadUrl = window.URL.createObjectURL(blob);
saveAs(downloadUrl, 'photo-processed.jpg');

What am I doing wrong?

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