Categories
JavaScript Answers

How to convert blob from DataURL with JavaScript?

Spread the love

Sometimes, we want to convert blob from DataURL with JavaScript.

In this article, we’ll look at how to convert blob from DataURL with JavaScript.

How to convert blob from DataURL with JavaScript?

To convert blob from DataURL with JavaScript, we can use fetch.

For instance, we write

const url =
  "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==";

const res = await fetch(url);
const blob = await res.blob();

to call fetch with url to return a promise with the response.

Then we call res.blob to return a promise with the blob from the response object.

Conclusion

To convert blob from DataURL with JavaScript, we can use fetch.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *