chrome.fileBrowserHandler

Use the chrome.fileBrowserHandler API to extend the Chrome OS file browser. For example, you can use this API to enable users to upload files to your website.

Availability:

Since Chrome 16.

Permissions:

"fileBrowserHandler"

Important:
This API works only on Chrome OS.

The Chrome OS file browser comes up when
the user either presses Alt+Shift+M
or connects an external storage device,
such as an SD card, USB key, external drive, or digital camera.
Besides showing the files on external devices,
the file browser can also display files
that the user has previously saved to the system.

When the user selects one or more files,
the file browser adds buttons
representing the valid handlers for those files.
For example, in the following screenshot,
selecting a file with a ".jpg" suffix
results in an "Upload to Picasa" button that the user can click.

Manifest

You must declare the "fileBrowserHandler" permission
in the extension manifest,
and you must use the "file_browser_handlers" field
to register the extension as a handler of at least one file type.
You should also provide a 16x16 icon
to be displayed on the button.
For example:

Implementing a file browser handler

To use this API,
you must implement a function that handles the onExecute event
of chrome.fileBrowserHandler.
Your function will be called whenever the user clicks the button
that represents your file browser handler.
In your function, use the HTML5
FileSystem API
to get access to the file contents.
Here is an example:

Methods

selectFile

Prompts user to select file path under which file should be saved. When the file is selected, file access permission required to use the file (read, write and create) are granted to the caller. The file will not actually get created during the function call, so function caller must ensure its existence before using it. The function has to be invoked with a user gesture.

Parameters

object

selectionParams

Parameters that will be used while selecting the file.

string

suggestedName

Suggested name for the file.

array of string

(optional)
allowedFileExtensions

Since Chrome 23.

List of file extensions that the selected file can have. The list is also used to specify what files to be shown in the select file dialog. Files with the listed extensions are only shown in the dialog. Extensions should not include the leading '.'. Example: ['jpg', 'png']