• Skip to main content
  • Select language
  • Skip to search
MDN Web Docs
  • Technologies
    • HTML
    • CSS
    • JavaScript
    • Graphics
    • HTTP
    • APIs / DOM
    • WebExtensions
    • MathML
  • References & Guides
    • Learn web development
    • Tutorials
    • References
    • Developer Guides
    • Accessibility
    • Game development
    • ...more docs
B2G OS
  1. MDN
  2. Archive of obsolete content
  3. B2G OS
  4. B2G OS APIs
  5. DeviceStorage
  6. DeviceStorage.add()

DeviceStorage.add()

In This Article
  1. Summary
  2. Syntax
    1. Parameters
    2. Returns
  3. Example
  4. Specification
  5. See also

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

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

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

  • DeviceStorage
  • Blob
  • DOMRequest
  • Device Storage API

Document Tags and Contributors

Tags: 
  • API
  • B2G
  • Device Storage
  • Firefox OS
  • Method
  • Non Standard
  • Reference
  • Référence
  • WebAPI
 Contributors to this page: chrisdavidmills, fscholz, kscarfone, Jeremie
 Last updated by: chrisdavidmills, Feb 27, 2017, 2:08:08 AM
See also
  1. Device Storage API
  2. Archive
  3. Events
    1. change
  4. Related pages for Device Storage API
    1. DeviceStorage
    2. DeviceStorageChangeEvent
    3. Navigator.getDeviceStorage()