Usage

The mediaGalleries API lets you prompt the user for permission to access media galleries on the user's computer. The permission dialog contains common media locations for the platform and allows the user to specify additional locations. From those locations, only media files will be present in the file system objects.

Manifest

The media galleries API has two axes of permission parameters:

These two axes and the permission parameters on each axis are described in the table below:

Axis Parameter Effect
Locations none If you do not specify a location permission parameter, your app will not be able to access any media galleries until the user grants permission to access specific media galleries at runtime using the media gallery permission dialog.
"allAutoDetected" Grants your app access to all auto-detected media galleries on the user's computer. This permission causes an install-time prompt to be displayed indicating that the app will have access to the user's media files.
Access type "read" Grants your app the right to read files in media galleries.
"delete" Grants your app the right to delete files from media galleries. "read" permission is a prerequisite for "delete". Specify both "read" and "delete" to obtain both types of permissions to media galleries.
"copyTo" Grants your app the right to copy files into media galleries. Only valid media files that Chrome is capable of playing or displaying are permitted; files that Chrome is not able to validate will result in a security error. "read" and "delete" permissions are prerequisites for "copyTo". Specify "read", "delete" and "copyTo" to obtain all three types of permissions to media galleries.

Notes:

Below is an example of a manifest file with mediaGalleries permissions:

{
  "name": "My app",
  ...
  "permissions": [
    { "mediaGalleries": ["read", "allAutoDetected"] }
  ],
  ...
}

This example manifest file will trigger an install-time permission prompt, and let the app read from all auto-detected media galleries on the user's computer. The user may add or remove galleries using the media gallery permission dialog, after which the app will be able to read all the media files from galleries that the user selected.

iTunes

If present, the user's iTunes library can be accessed as a media gallery. In addition to the media files in the library, the "iTunes Music Library.xml" file is also presented.

Regardless of where the music files are actually on the disk (and where the xml file says they are), they are mapped into an Artist/Album/Track hierarchy like iTunes does by default. This mapping doesn't always work perfectly, so there are two things to note for Apps trying to match the xml file with files in the gallery.

If the filenames for tracks within an album are not unique, they will be uniquified by adding the track id in parentheses before the extension, and if there is a colon or a slash in the artist, album, or track name, they are turned into underscore characters.

Picasa

If present, the user's Picasa library can also be accessed as a media gallery. Directories on the filesystem scanned by Picasa are presented under folders/. Picasa Albums are presented under albums/.

Albums and Folders that have duplicate names and dates will be uniquified using an incrementing integer in parenthesis before the extension.

Duplicate filenames within the same Album will also be uniquified using an incrementing integer in parenthesis before the extension.

iPhoto

If present, the user's iPhoto library can be accessed as a media gallery. The files are structured within a subdirectory called "Albums/". Within that subdirectory, each album in the user's iPhoto library will appear as a subdirectory by name, and contain file entries for the photos in that album.

Duplicate album names or image filenames within albums will get a disambiguating suffix like "(NN)" where NN is a unique number.

Any items appearing in multiple albums in iPhoto will appear in all those albums in the gallery.

If the user has modified any images within an album, there will be an additional subdirectory called "originals/" within the album directory. It will contain the original image with the same filename as in the parent album subdirectory. The file as it appears in the parrent album directory will be the one the user has invested time cropping, rotating, or otherwise editing.