Skip to content Skip to sidebar Skip to footer

What Is A Javascript Blob Object, Why Is It Useful?

I recently ran into the JavaScript Blob object, I used it to initialize a web worker where the code was contained within a script tag in the document. Based on the MDN documentatio

Solution 1:

Blobs aren't terribly useful on their own. What's useful about them is that they work with many calls which are meant to process Files. The most important of these is URL.createObjectURL(), which can be used to create a URL you can then use in the href or src attributes of HTML tags, @import statements and url() values in CSS, etc.

Basically, Blob gives JavaScript something like temporary files, and URL.createObjectURL() lets you treat those blobs as though they were files on a web server.

Solution 2:

You may need to send through an API where a URL is expecting data that is file-like.

Blobs allow you to construct file like objects on the client that you can pass to apis that expect urls instead of requiring the server provides the file.

See more here.

Post a Comment for "What Is A Javascript Blob Object, Why Is It Useful?"