expo-media-library
Version: 55.0.6 Provides access to the user’s media library, allowing you to read, create, and manage photos and videos on the device. Works with the camera roll on iOS and the media store on Android.Installation
Usage
API Reference
Methods
(options?: AssetQueryOptions) => Promise<PagedInfo>
Retrieves assets from the media library
(asset: Asset | string) => Promise<AssetInfo>
Gets detailed information about a specific asset
(localUri: string) => Promise<Asset>
Saves a file to the media library
(localUri: string) => Promise<void>
Saves an image or video to the library
(assets: Asset[] | string[]) => Promise<boolean>
Deletes assets from the library
(options?: AlbumQueryOptions) => Promise<Album[]>
Gets list of albums
(title: string) => Promise<Album | null>
Gets album by title
(albumName: string, asset?: Asset | string, copyAsset?: boolean) => Promise<Album>
Creates a new album
(assets: Asset[] | string[], album: Album | string, copyAssets?: boolean) => Promise<boolean>
Adds assets to an album
(assets: Asset[] | string[], album: Album | string) => Promise<boolean>
Removes assets from an album
(albums: Album[] | string[]) => Promise<boolean>
Deletes albums
(writeOnly?: boolean) => Promise<PermissionResponse>
Requests media library permissions
(writeOnly?: boolean) => Promise<PermissionResponse>
Checks current permission status
Hooks
(options?: { writeOnly?: boolean }) => [PermissionResponse | null, () => Promise<PermissionResponse>, () => Promise<PermissionResponse>]
Hook for managing permissions
Types
Asset
string
Asset identifier
string
File name
string
Asset URI
MediaType
Type:
'photo', 'video', 'audio', 'unknown'number
Width in pixels
number
Height in pixels
number
Creation timestamp
number
Modification timestamp
number
Duration for videos in seconds
AssetInfo
ExtendsAsset with additional fields:
string
Local file URI
Location
GPS location data
object
EXIF metadata
boolean
Whether asset is marked as favorite
Album
string
Album identifier
string
Album name
number
Number of assets in album
string
Album type
Examples
Load Recent Photos
Paginated Asset Loading
Save Image to Library
Get Asset Details
Manage Albums
Delete Assets
Complete Photo Gallery Example
Platform Support
Permissions
iOS
Add toapp.json:
Android
Permissions automatically added:READ_EXTERNAL_STORAGE/READ_MEDIA_IMAGES/READ_MEDIA_VIDEO(for reading)WRITE_EXTERNAL_STORAGE(for writing on Android < 10)ACCESS_MEDIA_LOCATION(for location data)
Best Practices
- Pagination: Use
firstandafterfor efficient loading - Permission Check: Always check permissions before operations
- Asset Caching: Cache asset URIs to avoid repeated queries
- Delete Carefully: Confirm before deleting user photos
- Album Organization: Group related photos in albums