Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is a JavaScript Blob object, why is it useful?

Tags:

javascript

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 documentation:

A Blob object represents a file-like object of immutable, raw data. Blobs represent data that isn't necessarily in a JavaScript-native format.

It sounds like it acts as a sack to put a collection of things into that all share a MIME type. Am I wrong in this opinion, is this opinion incomplete?

Why is the object needed/useful?

like image 683
robbmj Avatar asked Mar 14 '15 23:03

robbmj


People also ask

What are Blob used for in JavaScript?

The blob object is used for representing a blob object which is immutable and is used for representing raw data. The blob has a size and mime type property just like a file has. File is a derivation of blob and blob can be used in places where the file is used.

What is the purpose of a Blob?

A blob is a data type that can store binary data. This is different than most other data types used in databases, such as integers, floating point numbers, characters, and strings, which store letters and numbers. Since blobs can store binary data, they can be used to store images or other multimedia files.

What is a Blob URL and why it is used?

Blob URLs contain pseudo protocols that can create a temporary URL to audio and video files. This type of URL essentially acts as a fake source for the media on the website, so you can't download it directly. Instead, you have to use third-party conversion tools.

What does Blob mean in programming?

Binary large object (BLOB) is a generic term used to describe the handling and storage of long strings of data by database management systems.


1 Answers

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.

like image 141
Becca Royal-Gordon Avatar answered Sep 23 '22 01:09

Becca Royal-Gordon