DeviceStorage.freeSpace()

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

Summary

The freeSpace method is used to get the amount of free space usable by the storage area.

The request's result is a number representing the amount of free space expressed in Bytes.

Syntax

JavaScript
var instanceOfDOMRequest = instanceOfDeviceStorage.freeSpace();

Returns

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

Example

JavaScript
var sdcard = navigator.getDeviceStorage("sdcard");</code><code class="language-js">

var request = sdcard.freeSpace();

request.onsuccess = function () {
  // The result is expressed in bytes, let's turn it into Gigabytes
  var size = this.result / Math.pow(10,9);

  console.log("You have " + size.toFixed(2) + "GB of free space on your SDCard.");
}

request.onerror = function () {
  console.warn("Unable to get the free space available for the SDCard: " + 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/freespace

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