2 The Chrome OS file browser comes up when
3 the user either presses Alt+Shift+M
4 or connects an external storage device,
5 such as an SD card, USB key, external drive, or digital camera.
6 Besides showing the files on external devices,
7 the file browser can also display files
8 that the user has previously saved to the system.
12 When the user selects one or more files,
13 the file browser adds buttons
14 representing the valid handlers for those files.
15 For example, in the following screenshot,
16 selecting a file with a
".jpg" suffix
17 results in an
"Upload to Picasa" button that the user can click.
21 <img src=
"{{static}}/images/filebrowserhandler.png"
22 width=
"640" height=
"400" alt=
"file browser screenshot" />
26 <h2 id=
"manifest">Manifest
</h2>
29 You must declare the
"fileBrowserHandler" permission
30 in the
<a href=
"manifest">extension manifest
</a>,
31 and you must use the
"file_browser_handlers" field
32 to register the extension as a handler of at least one file type.
33 You should also provide a
16x16 icon
34 to be displayed on the button.
38 <pre data-filename=
"manifest.json">
40 "name":
"My extension",
42 <b>"file_browser_handlers"</b>: [
44 <b>"id"</b>:
"upload",
45 <b>"default_title"</b>:
"Save to Gallery",
<em>// What the button will display
</em>
46 <b>"file_filters"</b>: [
47 "filesystem:*.jpg",
<em>// To match all files, use
"filesystem:*.*"</em>
54 <b>"fileBrowserHandler"</b>
56 "icons": {
<b>"16"</b>:
"icon16.png",
58 "128":
"icon128.png" },
65 You can specify locale-specific strings for the value of
"default_title".
66 See
<a href=
"i18n">Internationalization (i18n)
</a> for details.
69 <h2 id=
"code">Implementing a file browser handler
</h2>
73 you must implement a function that handles the
<code>onExecute
</code> event
74 of
<code>chrome.fileBrowserHandler
</code>.
75 Your function will be called whenever the user clicks the button
76 that represents your file browser handler.
77 In your function, use the HTML5
78 <a href=
"http://www.html5rocks.com/tutorials/file/filesystem/">FileSystem API
</a>
79 to get access to the file contents.
83 <pre data-filename=
"background.js">
84 chrome.fileBrowserHandler.onExecute.addListener(function(id, details) {
86 var fileEntries = details.entries;
87 for (var i =
0, entry; entry = fileEntries[i]; ++i) {
88 entry.file(function(file) {
89 <em>// send file somewhere
</em>
97 Your event handler is passed two arguments:
102 <dd> The
"id" value from the manifest file.
103 If your extension implements multiple handlers,
104 you can check the
<code>id
</code> value
105 to see which handler has been triggered.
108 <dd> An object describing the event.
109 You can get the file or files that the user has selected
110 from the
<code>entries
</code> field of this object,
112 FileSystem
<code>Entry
</code> objects.
118 <h2 id="manifest_details">Manifest details</h2>
120 <p class="authornote">
121 {PENDING: give details about "id" and "default_title".
122 It should be unique within your extension -- don't worry about other extensions.
123 "default_title" implies that you can change the title,
124 but you can't aside from internationalizing it.
127 <p class="authornote">
128 {PENDING: give details about the file_filters entry.
129 File filters are currently case-sensitive, but we plan to change that.
130 Mention <code>filesystem:*.*</code>.
135 <h2 id="examples">Examples</h2>
138 For examples of using this API, see ...
139 For other examples and for help in viewing the source code, see
140 <a href="samples">Samples</a>.