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

310
Views
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
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!