The LocalFileSystemSync
interface of the File System API gives you access to a sandboxed file system. It is intended to be used with WebWorkers. The methods are implemented by worker objects.
About this document
This document was last updated on March 2, 2012 and follows the W3C Specifications (Working Draft) drafted on April 19, 2011.
Basic concepts
You can request access to a sandboxed file system by requesting LocalFileSystemSync
object from within a web worker. The global methods in the window
object requestFileSystemSync()
and resolveLocalFileSystemSyncURL()
methods are exposed to the Worker's global scope. Calling window.requestFileSystemSync()
for creates new storage for your web app.
For more concepts, see the counterpart article for the asynchronous API.
Example
//Taking care of the browser-specific prefix window.requestFileSystemSync = window.requestFileSystemSync || window.webkitRequestFileSystemSync; // The first parameter defines the type of storage: persistent or temporary // Next, set the size of space needed (in bytes) // initFs is the success callback // And the last one is the error callback // for denial of access and other errors. var fs = requestFileSystemSync(TEMPORARY, 1024*1024 /*1MB*/);
Because you are using a synchronous API, you don't need success and error callbacks.
Method overview
FileSystemSync requestFileSystemSync (in unsigned short type, in long long size) raises FileException; |
EntrySync resolveLocalFileSystemSyncURL (in DOMString url) raises FileException; |
Constants
Constant | Value | Description |
---|---|---|
TEMPORARY | 0 | Transient storage that can be be removed by the browser at its discretion. |
PERSISTENT | 1 | Storage that stays in the browser unless the user or the app expunges it. |
Methods
requestFileSystemSync()
Requests a file system where data should be stored. You access a sandboxed file system by requesting a LocalFileSystemSync
object from within a web worker using this global method, window.requestFileSystemSync()
. [ RESEARCH ]
FileSystemSync
requestFileSystemSync(
in unsigned short type,
in unsigned long long size
);
Parameters
- type
- The storage type of the file system. The values can be either
TEMPORARY
orPERSISTENT
. - size
- The storage space—in bytes—that you need for your app.
Returns
FileSystemSync
- An object that represents the file system.
Exceptions
This method can raise an FileException with the following code:
Exception | Description |
---|---|
SECURITY_ERROR | The application does not have permission to access the file system interface. For example, you cannot run from file:// . For more details, see the article on basic concepts. |
resolveLocalFileSystemSyncURL()
Allows the user to look up the Entry
for a file or directory referred to by a local URL.
void resolveLocalFileSystemURL( in DOMString url );
Parameter
- url
- The URL of a local file in the file system.
Returns
EntrySync
- An object that represents entries in the file system.
Exceptions
This method can raise an FileException with the following code:
ENCODING_ERR
- The syntax of the URL was invalid.
NOT_FOUND_ERR
- The URL was structurally correct, but refers to a resource that does not exist.
SECURITY_ERR
- The application does not have permission to access the file system interface.
Browser compatibility
{{ CompatibilityTable() }}
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari (WebKit) |
---|---|---|---|---|---|
Basic support | 13{{ property_prefix("webkit") }} | {{ CompatNo() }} | {{ CompatNo() }} | {{ CompatNo() }} | {{ CompatNo() }} |
Feature | Android | Chrome for Android | Firefox Mobile (Gecko) | IE Phone | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|---|
Basic support | {{ CompatNo() }} | 0.16{{ property_prefix("webkit") }} | {{ CompatNo() }} | {{ CompatNo() }} | {{ CompatNo() }} | {{ CompatNo() }} |
See also
Specification:{{ spec("https://dev.w3.org/2009/dap/file-system/pub/FileSystem/", "File API: Directories and System Specification", "WD") }}
Reference: File System API
Introduction: Basic Concepts About the File System API