Use Uri, not Base64, for Capacitor camera photos
Use CameraResultType.Uri with Capacitor's Camera plugin to avoid memory crashes from Base64 photo encoding.
02 Jan 2026, 00:14 UTC

The problem: your camera photo crashes the app
You install @capacitor/camera, call Camera.getPhoto(), and the app works on your phone. Then a tester on a low-end Android device captures a picture and the app terminates. The likely culprit is resultType: Base64. It encodes the entire image as a text string in memory, which can exhaust RAM on devices with limited heap space.
This post explains how to choose a safe output format, configure platform permissions, and verify the result on a real device.
Permission setup before you capture
Capacitor wraps native camera APIs, but it does not add platform permissions for you. On iOS, open ios/App/Info.plist and add:
<key>NSCameraUsageDescription</key>
<string>We need camera access to take photos for your profile.</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>We need photo library access to save and select images.</string>
On Android, open android/app/src/main/AndroidManifest.xml and add a uses-permission tag inside manifest:
<uses-permission android:name='android.permission.CAMERA' />
After editing, run npx cap sync in the project root so Xcode and Android Studio pick up the plugin and manifest changes. Missing iOS usage strings can cause silent denial or a crash instead of a permission prompt.
Choose the result type
Camera.getPhoto accepts a resultType option. The practical choices are:
| Option | What it returns | Best for |
|---|---|---|
| Uri | A file path or content URI to the captured image | Most apps; display in an or upload to a server |
| Base64 | The image encoded as a text string | Small images embedded directly in HTML or JSON |
| DataUrl | A data: URL containing the encoded image | Inline preview in a web view |
Base64 and DataUrl expand the image size by roughly one-third and keep it in JavaScript memory. On a high-resolution photo, that can trigger an out-of-memory crash on low-end Android devices. Uri avoids this by referencing a file instead of embedding it.
Worked example: capture and display a photo
Install the plugin:
npm install @capacitor/camera
npx cap sync
Run npm install in your project directory with normal user permissions. Run npx cap sync from the same directory; it modifies native project files, so close Xcode or Android Studio if you are editing generated files manually.
import { Camera, CameraResultType } from '@capacitor/camera';
async function takePhoto() {
const image = await Camera.getPhoto({
resultType: CameraResultType.Uri,
source: 'camera',
quality: 90,
});
const photoUrl = image.webPath ?? image.path;
document.getElementById('photo').src = photoUrl;
}
Expected check: on a physical iOS or Android device, tapping the capture button should show a native permission prompt the first time, then return a usable URI. Emulators and simulators may not expose a camera or may behave differently, so verify on real hardware.
Limitation: scoped storage and web fallbacks
Android 10 and later use scoped storage, which can restrict where captured files are written and whether other apps can access them. The web implementation may fall back to a file input and does not guarantee a native camera UI. Treat the returned URI as platform-specific until you test it.
Practical verification: after capturing, log the full result object and attempt to set it as an source. If the image appears, the URI is usable in your web view. If it is blank, inspect device logs for permission denials or storage errors.
Closing
Start with CameraResultType.Uri, add the required iOS and Android permission strings, run npx cap sync, and test on physical devices. Reserve Base64 for small images where you truly need inline data, and watch memory on low-end devices.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.