JavaScript Blob17 Mar 2025 | 5 min read Blobs are immutable objects that represent unprocessed data. The file is a Blob derived from data from the file system. Blobs allow us to create file-like objects on the client that we may transfer to APIs, and these APIs expect URLs rather than needing the server to provide the file. In this article, we are going to discuss the JavaScript Blob with some examples. What is a JavaScript Blob?A blob object is simply a collection of bytes that contains data stored in a file. A blob may appear to be a reference to the actual file, but it is not. A blob has the same size and MIME as a simple file. The blob data is stored in the user's memory, and it depends on the browser functions and the blob's size. The file is a derivation of the blob, and it may be used in the same places where the file is used. Blobs are very useful for storing binary data because their content can be easily read as an ArrayBuffer. Blobs can be stored in the memory or on disk by the web browser, and they can represent truly massive bits of data that are too large to fit in the main memory unless first separated into smaller pieces with the slice () method. The syntax for creating a blob:The syntax for creating a JavaScript blob may be defined as: In this syntax,
Example:Let's take an example to understand how to create a JavaScript blob in the program. Output: After executing this code, we will get the output as shown below in the screenshot. ![]() In this program, we just make a simple <p> element with id = "main". Blob ObjectThe blob object is used to represent an immutable blob object that represents raw data. The blob, like a file, has a size and mime-type property. Example:Let's take an example to understand how we can create a blob object in the JavaScript. Output: After executing this code, we will get the output as shown below in the screenshot. ![]() As we have seen, there is a "Click here" button. When we click on the "Click Here" button, it shows the result shown below in the screenshot. ![]() JavaScript Blob URL'sWe have Blob URLs that refer to the blob, same as we have file URLs that refer to actual files in the local filesystem. If blob URLs are similar to regular URLs, they can be used everywhere regular URLs can be used. A JavaScript blob may easily be used as a URL for <img> tag and other tags to display its contents. The createObjectURL object can be used to get the blob URL that points to a blob: Example:Let's take an example to understand how we can use the blob URL in the program. Output: After executing this code, we will get the output as shown below in the screenshot. ![]() Here, we can see there is a link. When we click on the link, a text file is a download from the link as shown below in the screenshot: ![]() Blob to base64Converting a Blob into a base64-encoded string is an alternative to URL.createObjectURL. This encoding protects binary data by encrypting it as a string of ultra-safe "readable" characters with ASCII codes ranging from 0 to 64. More importantly, this encoding can be used in "data-urls". To convert a Blob to base64, we'll use the built-in FileReader object. A data URL has the following syntax: Such URLs may be used anywhere, just like "regular" URLs. Example:Let's take an example to understand how we can use the blob to base64 in the JavaScript blob. Output: After executing this code, we will get the output as shown below in the screenshot. When we execute the program, it directly downloads the file at run time. ![]() Pros and Cons of JavaScript blobThere are some pros and cons of JavaScript Blob. Some of them are as follows: Pros of JavaScript Blob
Cons of JavaScript Blob
|
This section will discuss the Fibonacci series and how we can generate the . Fibonacci series is a series that generates subsequent series of numbers by the addition of the two ious numbers. The first two terms of the Fibonacci series are zero and one, respectively....
5 min read
In this chapter, you will learn how to generate random images on a webpage with the help of JavaScript. So, we will create different random image generator using JavaScript and HTML source code. Firstly, it requires an array to contain the URLs of images to...
8 min read
? JavaScript is a light-weight object-oriented programming language that is used by several websites for scripting the webpages. It is an interpreted, full-fledged programming language. JavaScript enables dynamic interactivity on websites when it is applied to an HTML document. JavaScript helps the users to build modern web...
3 min read
The onbeforeunload Event happens just before a document is unloaded. It displays a statement in a confirmation dialogue box to stay current page or go to the page using the provided link. You may ask the user whether they wish to stay on the...
4 min read
An Http cookie, also known as a web cookie, is a small piece of data that the server sends to the web browser. The browser may store the cookies and send them back to the server with other requests. The typical use of the cookies...
10 min read
JavaScript provides an efficient garbage collection for memory management. JavaScript automatically supports memory management and is invisible to us. When we create new objects, functions, primitives and variables, all these programming elements take memory. How does JavaScript manage these elements and cleans them? In this section,...
8 min read
displays the y-coordinates or height of the given element. The read-only MouseEvent offsetY attribute returns the y-coordinate of the mouse cursor for the target element. We can add the event function on the div tag, web page, or other elements to display y-coordination. Syntax The following...
3 min read
A parent node in JavaScript may have one or more child elements in JavaScript. Now how to fetch those child elements of a node in JavaScript is the question. In this section, we will discuss and look at how we can get child elements of a...
3 min read
? Yes, it is a case sensitive language, which means the identifiers, keywords, variables, and function names must be written with a consistent capitalization of letters. Like many other programming languages, JavaScript has a set of rules for writing JavaScript programs or codes. Using the correct capitalization...
2 min read
() is a method of Element class that lets us scroll an element into the viewing portion of the window. Here, in this section, we will learn how we can use the scrollIntoView () method for scrolling the elements into the view. We will also...
4 min read
We request you to subscribe our newsletter for upcoming updates.
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India