Blob()
The Blob()
constructor creates a Blob
object, which represents a file-like object of immutable, raw data.
Syntax
new Blob()
new Blob(array)
new Blob(array, options)
Note:
Blob()
can only be constructed withnew
. Attempting to call it withoutnew
throws aTypeError
.
Parameters
array
optional- : An array of values to include in the
Blob
. These can beArrayBuffer
,Blob
, or strings. If any of these elements is aBlob
, its content (and not the object itself) is copied into the Blob being constructed.
- : An array of values to include in the
options
optional- : An object containing optional attributes for the
Blob
.type
- : A string indicating the MIME type of the data. The default value is the empty string
""
.
- : A string indicating the MIME type of the data. The default value is the empty string
endings
- : A string indicating how to handle line endings in the data. This can be either
"transparent"
(default) to keep line endings unchanged, or"native"
to convert line endings to the platform's native line endings (e.g.,\r\n
on Windows).
- : A string indicating how to handle line endings in the data. This can be either
- : An object containing optional attributes for the
Return value
A new Blob
object containing the specified data.
Description
Blob
objects represent data that isn't necessarily in a JavaScript-native format. The File
interface is based on Blob
, inheriting its functionality and expanding it to support files on the user's system.
To construct a Blob
from other non-blob objects and data, use the Blob()
constructor. To create a blob that contains a subset of another blob's data, use the slice()
method.
The type
property of a Blob
object will match the MIME type specified in the constructor's options
parameter, defaulting to an empty string if not specified.