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

315
Visualizações
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 à 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