Blob

< apis‎ | file
Jump to: navigation, search

Blob

This page has been flagged with the following issues:

High-level issues:


W3C Working Draft

Summary

The Blob object represents immutable raw data. It provides a method to slice data objects between ranges of bytes into further chunks of raw data.


Overview

Blob provides an attribute representing the size of the chunk of data. The File object inherits from the Blob object. Blob objects can be read asynchronously only on the main thread via FileReader objects, but metadata access via attributes such as size and type return synchronously (this trade-off is based on the underlying assumption that metadata access will not significantly block or disrupt the browser's main thread, whereas reading Blob data will).

Properties

No properties.

Methods

API Name Summary
close Releases the file lock for the associated file resource or frees the memory for the Blob object. After calling this method, performing addition operations on the Blob object fails and throws an exception.
slice Returns a new Blob object with bytes ranging from its optional start parameter up to but not including its optional end parameter.


Events

No events.

Examples

// Example for creating a URL to a typed array using a blob

JavaScript

var typedArray = GetTheTypedArraySomehow();
var blob = new Blob([typedArray], {type: "application/octet-binary"}); // pass a useful mime type here
var url = URL.createObjectURL(blob);
// url will be something like: blob:d3958f5c-0777-0845-9dcf-2cb28783acaf
// now you can use the url in any context that regular URLs can be used in, for example img.src, etc.

// Blob constructor example usage

JavaScript

var aFileParts = ['<a id="a">hey!</a>'];
var oMyBlob = new Blob(aFileParts, { "type" : "text/xml" }); // the blob



Related specifications

Specification Status Related Changes
W3C File API Specification W3C Working Draft

Compatibility

Desktop

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic Support 22.0
15.0
10.0
12.1
6.0

Mobile

Feature Android BlackBerry Chrome for mobile Firefox Mobile (Gecko) IE Mobile Opera Mobile Opera Mini Safari Mobile
Basic Support 3.0
10.0
18
?
?
?
Unsupported
6.0


Compatibility notes

Browser Version Note
Chrome on Android 18 while window.Blob is defined, it can't be used as a constructor; you should fallback on BlobBuilder
Safari 6 Blob constructor does not work correctly with ArrayViews. You always have to pass concrete ArrayBuffer to the constructor.

Attribution

This article contains content originally from external sources.

Portions of this content come from the Mozilla Developer Network cc-by-sa-small-wpd.svg: Article

Portions of this content come from the Microsoft Developer Network: Windows Internet Explorer API reference Article