Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

Revision 1121831 of File and Directory Entries API

  • Revision slug: Web/API/File_and_Directory_Entries_API
  • Revision title: File and Directory Entries API
  • Revision id: 1121831
  • Created:
  • Creator: Sheppy
  • Is current revision? No
  • Comment

Revision Content

{{DefaultAPISidebar("File System API")}}{{Non-standard_header}}

The File and Directory Entries API simulates a local file system that web apps can navigate within. You can develop apps which read, write, and create files and/or directories in a virtual, sandboxed file system.

Because this is a non-standard API, whose specification is not currently on a standards track, it's important to keep in mind that not all browsers implement it, and those that do may implement only small portions of it. Check the {{anch("Browser compatibility")}} section for details.

Two very similar APIs exist depending on whether you desire asynchronous or synchronous behavior. The synchronous API is indended to be used inside a {{domxref("Worker")}} and will return the values you desire. The asynchronous API will not block and functions and the API will not return values; instead, you will need to supply a callback function to handle the response whenever it arrives.

The Firefox implementation of the File and Directory Entries API is very limited; there is no support for creating files. Only for accessing files which are selected by the user in a file {{HTMLElement("input")}} element (see {{domxref("HTMLInputElement")}} as well) or when a file or directory is provided to the Web site or app using drag and drop. Firefox also does not implement the synchronous API. Check the browser compatibility for any part of the API you use carefully, and see File and Directory Entries API support in Firefox for more details.

Asynchronous API

The asynchronous API should be used for most operations, to prevent file system accesses from blocking the entire browser if used on the main thread. It includes the following interfaces:

  • LocalFileSystem has two global methods that lets you request access to a sandboxed file system: requestFileSystem() and resolveLocalFileSystemURL().  The methods are implemented by both the window object and the worker global scope.
  • FileSystem represents a file system. The object is your gateway to the entire API.
  • Entry represents an entry in a file system. The entry can be a file or a directory.
  • DirectoryEntry represents a directory in a file system. 
  • DirectoryReader lets you read files and directories in a directory.
  • FileEntry represents a file on a file system.
  • FileError is an error that you might encounter while using the asynchronous methods.

Synchronous API

The synchronous API is for use with WebWorkers. Unlike the asynchronous API, the synchronous API does not use callbacks because the API methods return values.

  • LocalFileSystemSync has two global methods that lets you request access to a sandboxed file system: requestFileSystemSync() and  resolveLocalFileSystemSyncURL(). The methods are implemented by the worker object.
  • FileSystemSync represents a file system.
  • EntrySync represents an entry in a file system. The entry can be a file or a directory.
  • DirectoryEntrySync represents a directory on a file system. 
  • DirectoryReaderSync lets you read files and directories in a directory.
  • FileEntrySync represents a file on a file system.
  • FileException is an error that you might encounter while using the synchronous methods.

Specifications

Specification Status Comment
{{SpecName('File System API')}} {{Spec2('File System API')}} Draft of proposed API

This API has no official W3C or WHATWG specification.

Browser compatibility

{{CompatibilityTable}}
Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Asynchronous API 13 {{ property_prefix("webkit") }} {{ CompatGeckoDesktop(50) }}[1] {{ CompatNo }} {{ CompatNo }} {{ CompatNo }}
Synchronous API 13 {{ property_prefix("webkit") }} {{ CompatNo }} {{ CompatNo }} {{ CompatNo }} {{ CompatNo }}
Feature Android Chrome for Android Firefox Mobile (Gecko) IE Phone Opera Mobile Safari Mobile
Asynchronous API {{ CompatNo }} {{ CompatVersionUnknown }} {{ property_prefix("webkit") }} {{ CompatGeckoMobile(50) }}[1] {{ CompatNo }} {{ CompatNo }} {{ CompatNo }}
Synchronous API {{ CompatNo }} {{ CompatVersionUnknown }} {{ property_prefix("webkit") }} {{ CompatNo }} {{ CompatNo }} {{ CompatNo }} {{ CompatNo }}

[1] Firefox 50 introduces partial support for the File and Directory Entries API. Be sure to check the compatibility tables for individual interfaces and methods before using them, to ensure that they're supported, before you use them. The API can be disabled by setting the value of the preference dom.webkitBlink.filesystem.enabled to false.

See also

  • Introduction to the File and Directory Entries API

Revision Source

<p>{{DefaultAPISidebar("File System API")}}{{Non-standard_header}}</p>

<p>The File and Directory Entries API simulates a local file system that web apps can navigate within. You can develop apps which read, write, and create files and/or directories in a virtual, sandboxed file system.</p>

<div class="note">
<p>Because this is a non-standard API, whose specification is not currently on a standards track, it's important to keep in mind that not all browsers implement it, and those that do may implement only small portions of it. Check the {{anch("Browser compatibility")}} section for details.</p>
</div>

<p>Two very similar APIs exist depending on whether you desire asynchronous or synchronous behavior. The synchronous API is indended to be used inside a {{domxref("Worker")}} and will return the values you desire. The asynchronous API will not block and functions and the API will not return values; instead, you will need to supply a callback function to handle the response whenever it arrives.</p>

<div class="warning">
<p>The Firefox implementation of the File and Directory Entries API is very limited; there is no support for creating files. Only for accessing files which are selected by the user in a file {{HTMLElement("input")}} element (see {{domxref("HTMLInputElement")}} as well) or when a file or directory is provided to the Web site or app using <a href="/en-US/docs/Web/API/HTML_Drag_and_Drop_API">drag and drop</a>. Firefox also does not implement the synchronous API. Check the browser compatibility for any part of the API you use carefully, and see <a href="/en-US/docs/Web/API/File_and_Directory_Entries_API/Firefox_support">File and Directory Entries API support in Firefox</a> for more details.</p>
</div>

<h2 id="Asynchronous_API">Asynchronous API</h2>

<p>The asynchronous API should be used for most operations, to prevent file system accesses from blocking the entire browser if used on the main thread. It includes the following interfaces:</p>

<ul>
 <li><a href="/en/DOM/File_API/File_System_API/LocalFileSystem" title="en/DOM/File_API/File_System_API/LocalFileSystem">LocalFileSystem</a> has two global methods that lets you request access to a sandboxed file system: requestFileSystem() and resolveLocalFileSystemURL().&nbsp; The methods are implemented by both the <a href="/en/DOM/window" title="https://developer.mozilla.org/en/DOM/window">window</a> object and the worker global scope.</li>
 <li><a href="/en/DOM/File_API/File_System_API/FileSystem" title="en/DOM/File_API/File_system_API/FileSystem">FileSystem</a> represents a file system. The object is your gateway to the entire API.</li>
 <li><a href="/en/DOM/File_API/File_System_API/Entry" title="en/DOM/File_API/File_system_API/Entry">Entry</a> represents an entry&nbsp;in a file system. The entry can be a file or a directory.</li>
 <li><a href="/en/DOM/File_API/File_System_API/DirectoryEntry" title="en/DOM/File_API/File_system_API/DirectoryEntry">DirectoryEntry</a> represents a directory in a file system.&nbsp;</li>
 <li><a href="/en/DOM/File_API/File_System_API/DirectoryReader" title="en/DOM/File_API/File_system_API/DirectoryReader">DirectoryReader</a> lets you read files and directories in a directory.</li>
 <li><a href="/en/DOM/File_API/File_System_API/FileEntry" title="en/DOM/File_API/File_system_API/FileEntry">FileEntry</a> represents a file on a file system.</li>
 <li><a href="/en/DOM/File_API/File_System_API/FileError" title="en/DOM/File_API/File_system_API/FileError">FileError</a> is an error&nbsp;that you might encounter while using the asynchronous methods.</li>
</ul>

<h2 id="Synchronous_API">Synchronous API</h2>

<p>The synchronous API is for use with&nbsp;<a href="/En/Using_web_workers" rel="internal" title="https://developer.mozilla.org/En/Using_web_workers">WebWorkers</a>. Unlike the asynchronous API, the synchronous API does not use callbacks because the API methods return values.</p>

<ul>
 <li><a href="/en/DOM/File_API/File_System_API/LocalFileSystemSync" title="en/DOM/File_API/File_System_API/LocalFileSystemSync">LocalFileSystemSync</a>&nbsp;has two global methods that lets you request access to a sandboxed file system:&nbsp;requestFileSystemSync()&nbsp;and&nbsp;&nbsp;resolveLocalFileSystemSyncURL(). The methods are implemented by the worker&nbsp;object.</li>
 <li><a href="/en/DOM/File_API/File_System_API/FileSystemSync" title="en/DOM/File_API/File_system_API/FileSystemSync">FileSystemSync</a> represents a file system.</li>
 <li><a href="/en/DOM/File_API/File_System_API/EntrySync" title="en/DOM/File_API/File_system_API/EntrySync">EntrySync</a> represents an entry in a file system. The entry can be a file or&nbsp;a directory.</li>
 <li><a href="/en/DOM/File_API/File_System_API/DirectoryEntrySync" title="en/DOM/File_API/File_system_API/DirectoryEntrySync">DirectoryEntrySync</a>&nbsp;represents a directory on a file system.&nbsp;</li>
 <li><a href="/en/DOM/File_API/File_System_API/DirectoryReaderSync" title="en/DOM/File_API/File_system_API/DirectoryReaderSync">DirectoryReaderSync</a>&nbsp;lets you read&nbsp;files and directories in a directory.</li>
 <li><a href="/en/DOM/File_API/File_System_API/FileEntrySync" title="en/DOM/File_API/File_system_API/FileEntrySync">FileEntrySync</a> represents a file on a file system.</li>
 <li><a href="/en/DOM/File_API/File_System_API/FileException" title="en/DOM/File_API/File_system_API/FileException">FileException</a> is an error&nbsp;that you might encounter while using the synchronous methods.</li>
</ul>

<h2 id="Specifications">Specifications</h2>

<table class="standard-table">
 <thead>
  <tr>
   <th scope="col">Specification</th>
   <th scope="col">Status</th>
   <th scope="col">Comment</th>
  </tr>
 </thead>
 <tbody>
  <tr>
   <td>{{SpecName('File System API')}}</td>
   <td>{{Spec2('File System API')}}</td>
   <td>Draft of proposed API</td>
  </tr>
 </tbody>
</table>

<p>This API has no official W3C or WHATWG specification.</p>

<h2 id="Browser_compatibility">Browser compatibility</h2>

<div>{{CompatibilityTable}}</div>

<div id="compat-desktop">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Feature</th>
   <th>Chrome</th>
   <th>Firefox (Gecko)</th>
   <th>Internet Explorer</th>
   <th>Opera</th>
   <th>Safari</th>
  </tr>
  <tr>
   <td>Asynchronous API</td>
   <td>13 {{ property_prefix("webkit") }}</td>
   <td>{{ CompatGeckoDesktop(50) }}<sup>[1]</sup></td>
   <td>{{ CompatNo }}</td>
   <td>{{ CompatNo }}</td>
   <td>{{ CompatNo }}</td>
  </tr>
  <tr>
   <td>Synchronous API</td>
   <td>13 {{ property_prefix("webkit") }}</td>
   <td>{{ CompatNo }}</td>
   <td>{{ CompatNo }}</td>
   <td>{{ CompatNo }}</td>
   <td>{{ CompatNo }}</td>
  </tr>
 </tbody>
</table>
</div>

<div id="compat-mobile">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Feature</th>
   <th>Android</th>
   <th>Chrome for Android</th>
   <th>Firefox Mobile (Gecko)</th>
   <th>IE Phone</th>
   <th>Opera Mobile</th>
   <th>Safari Mobile</th>
  </tr>
  <tr>
   <td>Asynchronous API</td>
   <td>{{ CompatNo }}</td>
   <td>{{ CompatVersionUnknown }} {{ property_prefix("webkit") }}</td>
   <td>{{ CompatGeckoMobile(50) }}<sup>[1]</sup></td>
   <td>{{ CompatNo }}</td>
   <td>{{ CompatNo }}</td>
   <td>{{ CompatNo }}</td>
  </tr>
  <tr>
   <td>Synchronous API</td>
   <td>{{ CompatNo }}</td>
   <td>{{ CompatVersionUnknown }} {{ property_prefix("webkit") }}</td>
   <td>{{ CompatNo }}</td>
   <td>{{ CompatNo }}</td>
   <td>{{ CompatNo }}</td>
   <td>{{ CompatNo }}</td>
  </tr>
 </tbody>
</table>
</div>

<p>[1] Firefox 50 introduces partial support for the File and Directory Entries API. Be sure to check the compatibility tables for individual interfaces and methods before using them, to ensure that they're supported, before you use them. The API can be disabled by setting the value of the preference <code>dom.webkitBlink.filesystem.enabled</code> to <code>false</code>.</p>

<h2 id="See_also">See also</h2>

<ul>
 <li>Introduction to the File and Directory Entries API</li>
</ul>
Revert to this revision