{{APIRef("File API")}}{{ obsolete_header}}
The BlobBuilder
interface provides an easy way to construct {{domxref("Blob")}} objects. Just create a BlobBuilder
and append chunks of data to it by calling the {{manch("append")}} method. When you're done building your blob, call {{manch("getBlob")}} to retrieve a {{domxref("Blob")}} containing the data you sent into the blob builder.
BlobBuilder
interface has been deprecated in favor of the newly introduced {{domxref('Blob')}} constructor.Method overview
void append(in ArrayBuffer data); |
void append(in Blob data); |
void append(in String data, [optional] in String endings); |
Blob getBlob([optional] in DOMString contentType); |
File getFile(in DOMString name, [optional] in DOMString contentType); |
Methods
append()
Appends the contents of the specified JavaScript object to the {{domxref("Blob")}} being built. If the value you specify isn't a {{domxref("Blob")}}, ArrayBuffer
, or String
, the value is coerced to a string before being appended to the blob.
void append( in ArrayBuffer data ); void append( in Blob data ); void append( in String data, [optional] in String endings );
Parameters
data
- The data to append to the {{domxref("Blob")}} being constructed.
endings
- Specifies how strings containing
\n
are to be written out. This can be"transparent"
(endings unchanged) or"native"
(endings changed to match host OS filesystem convention). The default value is"transparent"
.
getBlob()
Returns the {{domxref("Blob")}} object that has been constructed using the data passed through calls to {{manch("append")}}.
Blob getBlob( in DOMString contentType {{optional_inline}} );
Parameters
- contentType {{optional_inline}}
- The MIME type of the data to be returned in the {{domxref("Blob")}}. This will be the value of the
Blob
object's type property.
Return value
A {{domxref("Blob")}} object containing all of the data passed to any calls to {{manch("append")}} made since the BlobBuilder
was created. This also resets the BlobBuilder
so that the next call to {{manch("append")}} is starting a new, empty blob.
getFile() {{non-standard_inline}}
Returns a {{domxref("File")}} object.
File getFile( in DOMString name, [optional] in DOMString contentType );
Parameters
- name
- The file name.
- contentType {{optional_inline}}
- The MIME type of the data to be returned in the {{domxref("File")}}. This will be the value of the
File
object's type property.
Return value
A {{domxref("File")}} object.
Browser compatibility
{{CompatibilityTable}}
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|
Basic support | 8[1] | {{CompatNo}}[2] | 10[3] | {{CompatNo}} | {{CompatNo}}[1] |
getfile() {{non-standard_inline}} |
{{CompatNo}} | {{CompatNo}} | {{CompatNo}} | {{CompatNo}} | {{CompatNo}} |
Feature | Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|
Basic support | 3[1] | {{CompatNo}}[2] | {{CompatNo}} | {{CompatNo}} | {{CompatNo}}[1] |
getfile() {{non-standard_inline}} |
{{CompatNo}} | {{CompatNo}} | {{CompatNo}} | {{CompatNo}} | {{CompatNo}} |
[1] WebKit implemented the API as WebKitBlobBuilder
, though it has deprecated it now and has made its support configurable. Currently Safari disables the feature in Nightly, so it likely won't ship in a final version. On the other hand, Chrome, which has supported it since Chrome 8, still enables the feature. So Chrome might continue to support the feature. (See this WebKit changeset for details).
[2] Gecko implemented the API as MozBlobBuilder
. Starting in Firefox 14, using MozBlobBuilder
will show a warning message in the web console that the use of MozBlobBuilder
is deprecated and suggests to use {{domxref("Blob")}} constructor instead. In Gecko 18.0 this feature was removed.
[3] Trident implements the API as MSBlobBuilder
.
See also
- {{spec("https://dev.w3.org/2009/dap/file-system/file-writer.html#idl-def-BlobBuilder", "File API Specification: BlobBuilder", "ED")}}
- {{domxref("Blob")}}
- {{domxref("File")}}