This documentation is available as Markdown for AI agents and LLMs. See the full Markdown index or append .md to any documentation URL.
Expo MediaLibrary (next)
A library that provides access to the device's media library.
expo-media-library provides access to the user's media library, allowing apps to read existing images and videos, as well as save new ones.
On Android, full access to the media library (the main purpose of this package) is allowed only for apps that require broad access to photos. See details on Google Play's Photo and Video Permissions policy.
Installation
If you are installing this in an existing React Native app, make sure to install expo in your project.
Usage
API
Classes
Type: Class extends Album
Album Properties
stringUnique identifier of the album.
Can be used to re-instantiate an Album later.
Album Methods
Adds an asset to the album.
Promise<void>A promise that resolves once the asset has been added.
Example
const asset = await Asset.create("file:///path/to/photo.png"); await album.add(asset);
A static function. Creates a new album with a given name and assets.
On Android, if assets are provided and moveAssets is true, the assets will be moved into the new album. If false or not supported, the assets will be copied.
A promise resolving to the created Album.
Example
const album = await Album.create("My Album", [asset]); console.log(await album.getTitle()); // "My Album"
Permanently deletes the album from the device. On Android, it deletes the album and all its assets. On iOS, it deletes the album but keeps the assets in the main library.
Promise<void>A promise that resolves once the deletion has completed.
Example
await album.delete();
A static function. Deletes multiple albums at once.
Promise<void>A promise that resolves once the albums have been deleted.
Example
const album = await Album.create("My Album", [asset]); await Album.delete([album]);
Gets the display title (name) of the album. Note that album titles are not guaranteed to be unique.
Promise<string>A promise resolving to the album’s title string.
Example
const title = await album.getTitle(); console.log(title); // "Camera"
Type: Class extends Asset
Asset Properties
stringID of the asset.
Can be used to re-instantiate an Asset later.
For android it is a contentUri and PHAsset localIdentifier URI for iOS.
Asset Methods
A static function. Creates a new asset from a given file path. Optionally associates the asset with an album. On Android, if not specified, the asset will be placed in the default "Pictures" directory.
A promise resolving to the created Asset.
Example
const asset = await Asset.create("file:///storage/emulated/0/DCIM/Camera/IMG_20230915_123456.jpg"); console.log(await asset.getFilename()); // "IMG_20230915_123456.jpg"
Deletes the asset from the device’s media store.
Promise<void>A promise that resolves once the deletion has completed.
Example
await asset.delete();
Gets the creation time of the asset.
Promise<number | null>A promise resolving to the UNIX timestamp in milliseconds, or null if unavailable.
Gets the duration of the asset.
Applies only to assets with media type MediaType.audio or MediaType.video.
For other media types, it returns null.
Promise<number | null>A promise resolving to the duration in milliseconds, or null if not applicable.
Gets the exif data of the MediaType.image asset.
On Android, this method requires the ACCESS_MEDIA_LOCATION permission to access location metadata.
Promise<undefined>A promise resolving to the exif data object or an empty object if the exif data is unavailable.
Gets the filename of the asset, including its extension.
Promise<string>A promise resolving to the filename string.
Gets the height of the asset in pixels. Only applicable for image and video assets.
Promise<number>A promise resolving to the height in pixels.
Gets the last modification time of the asset.
Promise<number | null>A promise resolving to the UNIX timestamp in milliseconds, or null if unavailable.
Gets the URI pointing to the asset’s location in the system.
Example, for Android: file:///storage/emulated/0/DCIM/Camera/IMG_20230915_123456.jpg.
Promise<string>A promise resolving to the string URI.
Gets the width of the asset in pixels. Only applicable for image and video assets.
Promise<number>A promise resolving to the width in pixels.
Type: Class extends Query
Query Methods
Filters assets to only those contained in the specified album.
QueryThe updated query object for chaining.
Filters assets where the specified field is equal to the given value.
QueryThe updated query object for chaining.
Executes the query and retrieves the matching assets.
A promise that resolves to an array of Asset objects that match the query criteria.
Example
const assets = await new Query() .eq(AssetField.MEDIA_TYPE, MediaType.IMAGE) .lte(AssetField.HEIGHT, 1080) .orderBy(AssetField.CREATION_TIME) .limit(20) .exe();
Filters assets where the specified field is greater than the given value.
QueryThe updated query object for chaining.
Limits the number of results returned by the query.
QueryThe updated query object for chaining.
Filters assets where the specified field is less than the given value.
QueryThe updated query object for chaining.
Filters assets where the specified field is less than or equal to the given value.
QueryThe updated query object for chaining.
Filters assets where the specified field's value is in the given array of values.
QueryThe updated query object for chaining.
Methods
Asks the user to grant permissions for accessing media in user's media library.
Promise<PermissionResponse>A promise that fulfils with [PermissionResponse](expo/#permissionresponse object.
Types
Literal type: string
Acceptable values are: 'audio' | 'photo' | 'video'