DeviceStorage.add()

This API is available on Firefox OS for privileged or certified applications only.

Summary

The add method is used to add a file inside a given storage area.

When a file is added with this method, its name is generated automatically and is available within the request's result which is a File object.

Syntax

JavaScript
var instanceOfDOMRequest = instanceOfDeviceStorage.add(file);

Parameters

file
A Blob object representing the file to add (note that a File object is also a Blob object).

Returns

It returns a DOMRequest object to handle the success or error of the operation.

Example

JavaScript
var sdcard = navigator.getDeviceStorage("sdcard");
var file   = new Blob(["This is a text file."], {type: "text/plain"});

var request = sdcard.add(file);

request.onsuccess = function () {
  var name = this.result.name;
  console.log('File "' + name + '" successfully wrote on the sdcard storage area');
}

// An error typically occur if a file with the same name already exist
request.onerror = function () {
  console.warn('Unable to write the file: ' + this.error);
}

Specification

Not part of any specification.

See also

License

© 2016 Mozilla Contributors
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-us/docs/web/api/devicestorage/add

API B2G Device Storage Firefox OS Method Reference Référence WebAPI