chrome.fileSystem

Description: Use the chrome.fileSystem API to create, read, navigate, and write to the user's local file system. With this API, Chrome Apps can read and write to a user-selected location. For example, a text editor app can use the API to read and write local documents. All failures are notified via chrome.runtime.lastError.
Availability: Since Chrome 23.
Permissions: "fileSystem"
{"fileSystem": ["write"]}
{"fileSystem": ["write", "retainEntries", "directory"]}
Learn More: Manage Data
Build Apps with AngularJS
Chrome Apps Office Hours: TextDrive and AngularJS

Summary

Types
ChildChangeType
Volume
Methods
getDisplayPath chrome.fileSystem.getDisplayPath(Entry entry, function callback)
getWritableEntry chrome.fileSystem.getWritableEntry(Entry entry, function callback)
isWritableEntry chrome.fileSystem.isWritableEntry(Entry entry, function callback)
chooseEntry chrome.fileSystem.chooseEntry(object options, function callback)
restoreEntry chrome.fileSystem.restoreEntry(string id, function callback)
isRestorable chrome.fileSystem.isRestorable(string id, function callback)
retainEntry string chrome.fileSystem.retainEntry(Entry entry)
requestFileSystem chrome.fileSystem.requestFileSystem(object options, function callback)
getVolumeList chrome.fileSystem.getVolumeList(function callback)
Events
onVolumeListChanged

Types

ChildChangeType

Type of a change happened to a child entry within a tracked directory.
Enum
"created", "removed", or "changed"

Volume

Since Chrome 44.

properties
string volumeId
boolean writable

Methods

getDisplayPath

chrome.fileSystem.getDisplayPath(Entry entry, function callback)

Get the display path of an Entry object. The display path is based on the full path of the file or directory on the local file system, but may be made more readable for display purposes.

Parameters
Entry entry

Since Chrome 31.

function callback

The callback parameter should be a function that looks like this:

function(string displayPath) {...};
string displayPath

getWritableEntry

chrome.fileSystem.getWritableEntry(Entry entry, function callback)

Get a writable Entry from another Entry. This call will fail with a runtime error if the application does not have the 'write' permission under 'fileSystem'. If entry is a DirectoryEntry, this call will fail if the application does not have the 'directory' permission under 'fileSystem'.

Parameters
Entry entry

Since Chrome 31.

function callback

The callback parameter should be a function that looks like this:

function(Entry entry) {...};
Entry entry

isWritableEntry

chrome.fileSystem.isWritableEntry(Entry entry, function callback)

Gets whether this Entry is writable or not.

Parameters
Entry entry

Since Chrome 31.

function callback

The callback parameter should be a function that looks like this:

function(boolean isWritable) {...};
boolean isWritable

chooseEntry

chrome.fileSystem.chooseEntry(object options, function callback)

Ask the user to choose a file or directory.

Parameters
object (optional) options
enum of "openFile", "openWritableFile", "saveFile", or "openDirectory" (optional) type

Type of the prompt to show. The default is 'openFile'.

openFile
Prompts the user to open an existing file and returns a FileEntry on success. From Chrome 31 onwards, the FileEntry will be writable if the application has the 'write' permission under 'fileSystem'; otherwise, the FileEntry will be read-only.
openWritableFile
Prompts the user to open an existing file and returns a writable FileEntry on success. Calls using this type will fail with a runtime error if the application doesn't have the 'write' permission under 'fileSystem'.
saveFile
Prompts the user to open an existing file or a new file and returns a writable FileEntry on success. Calls using this type will fail with a runtime error if the application doesn't have the 'write' permission under 'fileSystem'.
openDirectory
Prompts the user to open a directory and returns a DirectoryEntry on success. Calls using this type will fail with a runtime error if the application doesn't have the 'directory' permission under 'fileSystem'. If the application has the 'write' permission under 'fileSystem', the returned DirectoryEntry will be writable; otherwise it will be read-only. New in Chrome 31.
string (optional) suggestedName

The suggested file name that will be presented to the user as the default name to read or write. This is optional.

array of object (optional) accepts

The optional list of accept options for this file opener. Each option will be presented as a unique group to the end-user.

Properties of each object

string (optional) description

This is the optional text description for this option. If not present, a description will be automatically generated; typically containing an expanded list of valid extensions (e.g. "text/html" may expand to "*.html, *.htm").

array of string (optional) mimeTypes

Mime-types to accept, e.g. "image/jpeg" or "audio/*". One of mimeTypes or extensions must contain at least one valid element.

array of string (optional) extensions

Extensions to accept, e.g. "jpg", "gif", "crx".

boolean (optional) acceptsAllTypes

Whether to accept all file types, in addition to the options specified in the accepts argument. The default is true. If the accepts field is unset or contains no valid entries, this will always be reset to true.

boolean (optional) acceptsMultiple

Since Chrome 30.

Whether to accept multiple files. This is only supported for openFile and openWritableFile. The callback to chooseEntry will be called with a list of entries if this is set to true. Otherwise it will be called with a single Entry.

function callback

The callback parameter should be a function that looks like this:

function(Entry entry, array of FileEntry fileEntries) {...};
Entry (optional) entry
array of FileEntry (optional) fileEntries

Properties of each object

restoreEntry

chrome.fileSystem.restoreEntry(string id, function callback)

Since Chrome 29.

Returns the file entry with the given id if it can be restored. This call will fail with a runtime error otherwise.

Parameters
string id
function callback

The callback parameter should be a function that looks like this:

function(Entry entry) {...};
Entry entry

isRestorable

chrome.fileSystem.isRestorable(string id, function callback)

Since Chrome 29.

Returns whether the app has permission to restore the entry with the given id.

Parameters
string id
function callback

The callback parameter should be a function that looks like this:

function(boolean isRestorable) {...};
boolean isRestorable

retainEntry

string chrome.fileSystem.retainEntry(Entry entry)

Since Chrome 29.

Returns an id that can be passed to restoreEntry to regain access to a given file entry. Only the 500 most recently used entries are retained, where calls to retainEntry and restoreEntry count as use. If the app has the 'retainEntries' permission under 'fileSystem', entries are retained indefinitely. Otherwise, entries are retained only while the app is running and across restarts.

Parameters
Entry entry

Since Chrome 31.

requestFileSystem

chrome.fileSystem.requestFileSystem(object options, function callback)

Since Chrome 44.

Requests access to a file system for a volume represented by options.volumeId. If options.writable is set to true, then the file system will be writable. Otherwise, it will be read-only. The writable option requires the "fileSystem": {"write"} permission in the manifest. Available to kiosk apps running in kiosk session only. For manual-launch kiosk mode, a confirmation dialog will be shown on top of the active app window. In case of an error, fileSystem will be undefined, and chrome.runtime.lastError will be set.

Parameters
object options
string volumeId

The ID of the requested volume.

boolean (optional) writable

Whether the requested file system should be writeable, or read-only. By default read-only.

function callback

The callback parameter should be a function that looks like this:

function(FileSystem fileSystem) {...};
FileSystem (optional) fileSystem

getVolumeList

chrome.fileSystem.getVolumeList(function callback)

Since Chrome 44.

Returns a list of volumes available for requestFileSystem(). The "fileSystem": {"requestFileSystem"} manifest permission is required. Available to kiosk apps running in the kiosk session only. In case of an error, volumes will be undefined, and chrome.runtime.lastError will be set.

Parameters
function callback

The callback parameter should be a function that looks like this:

function(array of Volume volumes) {...};
array of Volume (optional) volumes

Events

onVolumeListChanged

Since Chrome 44.

Called when a list of available volumes is changed.

addListener

chrome.fileSystem.onVolumeListChanged.addListener(function callback)
Parameters
function callback

The callback parameter should be a function that looks like this:

function(object event) {...};
object event
array of Volume volumes