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

320
Views
Loading image with XHR without responseType set to blob

I have this situation in which I load an image with XMLHttpRequest but without setting responseType to blob. So I receive a string

enter image description here

My question is, is it still possible to render the image in this situation?

I tried, for example, to convert this string to a Blob

out = new Blob([imageString],  { type: 'image/png' });

but this doesn't render the expected image. Any suggestions?

DEMO

And here is how my node backend sends that image to the browser

app.get("/binary/*", (req: express.Request, res: express.Response) => {
  const file = binaryPath + '/test.jpg';
  res.sendFile(file);
});
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Finally got it: If you do not want to have xhr.responseType = 'blob' and you want to create a url from received data, then you need to set xhr.responseType = 'arraybuffer'. This allows to convert the binary xhr.response into a blob and then create a URL.createObjectURL.

The point is that when you do not set responseType to a binary type then you get the default xhr.responseType = 'text' and utf8 encoding. And then blob creation fails.

I have included this solution in your stackblitz.

about 4 years ago · Juan Pablo Isaza Report
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!