Skip to main content

@napacitor/camera

Camera and media plugin: take photos, record videos, and pick photos and videos from the media library. Wraps the .NET MAUI MediaPicker API.

Installation​

To use npm:

npm install @napacitor/camera

To use yarn:

yarn add @napacitor/camera

Sync native files:

npx nap sync

Usage​

import { Camera } from '@napacitor/camera';

// Whether the device supports taking photos / videos
const supported = await Camera.isCaptureSupported();

// ── Capture photo / video (returns null on cancel) ─────────
const photo = await Camera.capturePhoto({ title: 'Take one' });
if (photo) {
console.log(photo.name, photo.size, photo.contentType);
// photo.data is base64 content, ready to upload / preview
}

const video = await Camera.captureVideo();

// ── Pick from the media library (returns [] on cancel) ─────
// Single selection (default selectionLimit = 1)
const [single] = await Camera.pickPhotos();
if (single) {
console.log(single.name);
}

// Multiple selection with image processing (maps to MAUI MediaPickerOptions)
const photos = await Camera.pickPhotos({
title: 'Choose photos',
selectionLimit: 9,
maximumWidth: 1024,
maximumHeight: 768,
compressionQuality: 85,
});

const videos = await Camera.pickVideos({ selectionLimit: 3 });

How It Works​

Wraps the .NET MAUI MediaPicker.Default facade: capturePhoto() / captureVideo() call CapturePhotoAsync / CaptureVideoAsync (return FileResult?, null on cancel); pickPhotos() / pickVideos() call the .NET 10 PickPhotosAsync / PickVideosAsync methods (return a list; single selection sets SelectionLimit = 1, cancel returns an empty list); isCaptureSupported() reads IsCaptureSupported. Every method is invoked on the UI thread (required by MAUI, which handles permission checks and requests automatically), then each FileResult stream is read into memory and returned as base64 to JS; FullPath is only included when the platform provides it (not guaranteed to be a physical path).

Permissions​

Android​

Add the following to Platforms/Android/AndroidManifest.xml:

<!-- Needed for Picking photo/video -->
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" android:maxSdkVersion="32" />
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
<uses-permission android:name="android.permission.READ_MEDIA_VIDEO" />

<!-- Needed for Taking photo/video -->
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" android:maxSdkVersion="32" />

When targeting Android 11 (API 30) or higher, also add the package visibility declaration:

<queries>
<intent>
<action android:name="android.media.action.IMAGE_CAPTURE" />
</intent>
</queries>

Alternatively, declare the permissions in Platforms/Android/MainApplication.cs using [assembly: UsesPermission(...)] assembly attributes.

iOS​

Add the following to Platforms/iOS/Info.plist (each string is the reason shown to the user when requesting access):

<key>NSCameraUsageDescription</key>
<string>This app needs access to the camera to take photos.</string>
<key>NSMicrophoneUsageDescription</key>
<string>This app needs access to microphone for taking videos.</string>
<key>NSPhotoLibraryAddUsageDescription</key>
<string>This app needs access to the photo gallery for picking photos and videos.</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>This app needs access to photos gallery for picking photos and videos.</string>

Windows​

No additional configuration required.

API​

isCaptureSupported()​

Whether the device supports taking photos / videos.

Returns: Promise<boolean>

pickPhotos(options?)​

Opens the media browser to pick one or more photos; returns [] when the user cancels.

ParamType
optionsPickMediaOptions

Returns: Promise<MediaFile[]>

pickVideos(options?)​

Opens the media browser to pick one or more videos; returns [] when the user cancels.

ParamType
optionsPickMediaOptions

Returns: Promise<MediaFile[]>

capturePhoto(options?)​

Opens the camera to take a photo; returns null when the user cancels.

ParamType
optionsPickMediaOptions

Returns: Promise<MediaFile | null>

captureVideo(options?)​

Opens the camera to record a video; returns null when the user cancels.

ParamType
optionsPickMediaOptions

Returns: Promise<MediaFile | null>

Interfaces​

MediaFile​

PropTypeDescription
namestringFile name.
pathstringPhysical path when available from the platform (don't rely on it; use data for the content).
sizenumberFile size in bytes.
contentTypestringMedia content type (e.g. 'image/jpeg'), when available from the platform.
datastringFile content encoded as base64.

PickMediaOptions​

PropTypeDescription
titlestringPicker title (shown only on some operating systems).
selectionLimitnumberSelection limit (defaults to 1; 0 means no limit; some Android picker UIs don't enforce it, and it's not supported on Windows).
maximumWidthnumberImage processing: maximum width in pixels (scaled proportionally when exceeded).
maximumHeightnumberImage processing: maximum height in pixels (scaled proportionally when exceeded).
compressionQualitynumberImage processing: compression quality 0-100 (only for supported image formats).
rotateImagebooleanImage processing: whether to rotate the image according to EXIF orientation (defaults to true).
preserveMetaDatabooleanImage processing: whether to preserve image metadata.