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 (legacy)
A library that provides access to the device's media library.
The legacy version of the MediaLibrary API is included in the
expo-media-librarylibrary. It can be used alongside the class-basedexpo-media-libraryAPI, which is exposed from the root import. To use the legacy API, import it fromexpo-media-library/legacy.
expo-media-library provides access to the user's media library, allowing them to access their existing images and videos from your app, as well as save new ones. You can also subscribe to any updates made to the user's media library.
Android allows full access to the media library (which is the purpose of this package) only for applications needing 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.
Configuration in app config
You can configure expo-media-library using its built-in config plugin if you use config plugins in your project (Continuous Native Generation (CNG)). The plugin allows you to configure various properties that cannot be set at runtime and require building a new app binary to take effect. If your app does not use CNG, then you'll need to manually configure the library.
Example app.json with config plugin
{ "expo": { "plugins": [ [ "expo-media-library", { "photosPermission": "Allow $(PRODUCT_NAME) to access your photos.", "savePhotosPermission": "Allow $(PRODUCT_NAME) to save photos.", "isAccessMediaLocationEnabled": true, "granularPermissions": ["audio", "photo"] } ] ] } }
Configurable properties
Are you using this library in an existing React Native app?
If you're not using Continuous Native Generation (CNG) or you're using native android and ios projects manually, then you need to add following permissions and configuration to your native projects:
Android
-
To access asset location (latitude and longitude EXIF tags), add
ACCESS_MEDIA_LOCATIONpermission to your project's android/app/src/main/AndroidManifest.xml:<uses-permission android:name="android.permission.ACCESS_MEDIA_LOCATION" /> -
Scoped storage is available from Android 10. To make
expo-media-librarywork with scoped storage, you need to add the following configuration to your android/app/src/main/AndroidManifest.xml:<manifest ... > <application android:requestLegacyExternalStorage="true" ...> </manifest>
iOS
-
Add
NSPhotoLibraryUsageDescription, andNSPhotoLibraryAddUsageDescriptionkeys to your project's ios/[app]/Info.plist:<key>NSPhotoLibraryUsageDescription</key> <string>Give $(PRODUCT_NAME) permission to access your photos</string> <key>NSPhotoLibraryAddUsageDescription</key> <string>Give $(PRODUCT_NAME) permission to save photos</string>
Usage
Known limitations
Empty albums
Due to system limitations on Android, it is impossible to create empty albums. It is necessary to either pass an existing asset to add to the album or a URI of a local resource, which will be used to create a new asset inside the album.
Moving assets between albums
Android 11 introduced permission changes that make the operation of moving assets between albums require confirmation from the user every time.
Therefore, when creating a new asset, instead of creating the asset and then moving it to the album, it is recommended to pass the album parameter to the createAssetAsync method, which will automatically add the asset to the album without the need for user confirmation.
Wrong orientation of images
On Android, when using getAssetsAsync without resolveWithFullInfo: true, image orientation may be incorrect because EXIF data (which includes orientation) is only read when that option is enabled.
API
import * as MediaLibrary from 'expo-media-library/legacy';
No API data file found, sorry!
Permissions
Android
The following permissions are added automatically through this library's AndroidManifest.xml:
iOS
The following usage description keys are used by this library: