Capture Photos in Ionic with Capacitor Camera: A Practical Guide
Learn how to integrate Capacitor’s Camera plugin into an Ionic app, configure permissions, and avoid common mistakes. Includes a sample Angular service, platform‑specific steps, and verification tips.
08 Dec 2025, 18:22 UTC

Use Capacitor Camera in Ionic to Capture Photos
When building an Ionic app that needs to take pictures, the Capacitor Camera plugin gives a single API that works on iOS, Android, and the web. The core idea is to call Camera.getPhoto() with options, receive a Photo object, and then render or process the image. Below is the practical how‑to, from install to debugging.
Quick Answer
Install @capacitor/camera, add the required native permissions, and use a service like this:
import { Camera, CameraResultType } from '@capacitor/camera';
export class PhotoService {
async takePhoto() {
const photo = await Camera.getPhoto({
resultType: CameraResultType.Base64,
quality: 90,
source: CameraSource.Camera
});
return photo;
}
}
Display the image with <img [src]="photo.webPath">.
How It Works
The plugin bridges JavaScript and native APIs. On iOS and Android it uses the platform camera intent; on the web it falls back to the file‑input element. The returned Photo contains:
webPath– a URL usable in<img>base64String– the raw image data if requesteddataUrl– a base64 data URIfilePath– native file path (Android only)
Working Example
- Install the plugin
npm install @capacitor/camera npx cap sync - Create a service
// photo.service.ts import { Injectable } from '@angular/core'; import { Camera, CameraResultType, CameraSource } from '@capacitor/camera'; @Injectable({ providedIn: 'root' }) export class PhotoService { async capture(): Promise<any> { const photo = await Camera.getPhoto({ resultType: CameraResultType.Base64, quality: 80, source: CameraSource.Camera }); return photo; } } - Use in a component
// photo-page.component.ts import { Component } from '@angular/core'; import { PhotoService } from '../services/photo.service'; @Component({ selector: 'app-photo-page', templateUrl: './photo-page.component.html' }) export class PhotoPageComponent { photo: any; constructor(private photoSvc: PhotoService) {} async onTakePhoto() { this.photo = await this.photoSvc.capture(); } } - Template
<ion-button (click)="onTakePhoto()">Take Photo</ion-button> <ion-img *ngIf="photo" [src]="photo.webPath"></ion-img>
Platform‑Specific Configuration
Capacitor generates native projects. You must add permission strings before building.
iOS
// ios/App/App/Info.plist
NSCameraUsageDescription
We need camera access to capture photos.
Android
// android/app/src/main/AndroidManifest.xml
After editing, run npx cap sync android to propagate changes.
Common Pitfalls
- Missing Permissions – If
NSCameraUsageDescriptionorandroid.permission.CAMERAis omitted, the plugin will silently fail or throw an error. Check Logcat or Xcode console for “Permission denied”. - Wrong
qualityvalue – Thequalityoption must be 0–100. Values >100 are clamped to 100, but passingNaNyields a crash on Android. - Using
resultType: CameraResultType.Urion the web – The web fallback does not supportUri; it returns a data URL instead, causingphoto.webPathto be undefined. - Accessing
photo.filePathbefore the promise resolves – The file path is only available after the async call finishes. Trying to read it earlier will throw a runtime error. - Large images on the web – Browsers may reject files larger than ~5 MB or exceed memory limits. Prefer
quality: 70andresultType: CameraResultType.Base64for thumbnails.
Limitations and Edge Cases
- On the web, the plugin uses the
<input type="file">element, which requires a user gesture. Programmatic calls will be blocked by the browser. - iOS 14+ requires the
NSPhotoLibraryAddUsageDescriptionkey if you plan to save captured photos to the library. - Android 13+ introduces the
android.permission.CAMERA_ROLLfor saving to the gallery; add it if you implement that feature. - The
CameraSource.Promptoption shows both camera and gallery; on the web it opens the file picker only. - Memory usage scales with
qualityand image resolution. For high‑resolution images, consider usingCameraResultType.Urion native platforms and streaming the file to the server.
Verifying Success
- Run
ionic serveand click the button. The browser should open a file picker; select an image and confirm it renders. - On a device, run
ionic capacitor run ios --livereloadorionic capacitor run android --livereload. Tap the button; the native camera should launch, and the captured photo should appear. - Open Xcode or Android Studio logcat. Look for the permission prompt and ensure no error messages like
Permission deniedappear. - Inspect the
Photoobject in the console:console.log(photo). Verify thatwebPathis a valid URL andbase64Stringis non‑empty. - For production builds, test the app on both iOS and Android devices to confirm that the camera works after the app is installed.
Summary
Capacitor’s Camera plugin simplifies photo capture across platforms, but careful attention to permissions, option values, and platform quirks is essential. By following the installation steps, adding the required native keys, and handling the Photo object correctly, you can deliver a smooth camera experience in your Ionic app.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.