Capacitor Camera on IOS failed
See original GitHub issueBug Report
Capacitor Version
💊 Capacitor Doctor 💊
Latest Dependencies:
@capacitor/cli: 4.3.0
@capacitor/core: 4.3.0
@capacitor/android: 4.3.0
@capacitor/ios: 4.3.0
Installed Dependencies:
@capacitor/cli: 4.0.1
@capacitor/core: 4.0.1
@capacitor/android: 4.0.1
@capacitor/ios: 4.0.1
[success] iOS looking great! 👌
[success] Android looking great! 👌
Platform(s)
IOS
Current Behavior
When pick an image it says You don’t have permission to save the file [filepath] in the folder “com.apple.mobileslideshow.export-request”
Expected Behavior
I’m just picking an image and uploading it to server as base64
Code Reproduction
async newSelectImage() {
const image = await NCamera.getPhoto({
quality: 90,
allowEditing: false,
resultType: CameraResultType.Uri,
source: CameraSource.Prompt // Camera, Photos or Prompt!
});
if (image) {
this.saveImage(image)
}
}
// Create a new file from a capture image
async saveImage(photo: Photo) {
const base64Data = await this.readAsBase64(photo);
this.img = base64Data;
this.profile = base64Data;
}
private async readAsBase64(photo: Photo) {
if (this.platform.is('hybrid')) {
const file = await Filesystem.readFile({
path: photo.path
});
return file.data;
}
else {
// Fetch the photo, read as a blob, then convert to base64 format
const response = await fetch(photo.webPath);
const blob = await response.blob();
return await this.convertBlobToBase64(blob) as string;
}
}
// Helper function
convertBlobToBase64 = (blob: Blob) => new Promise((resolve, reject) => {
const reader = new FileReader;
reader.onerror = reject;
reader.onload = () => {
resolve(reader.result);
};
reader.readAsDataURL(blob);
});
Other Technical Details
npm --version
output: 8.19.2
node --version
output: v18.10.0
pod --version
output (iOS issues only): 1.11.3
Additional Context
Issue Analytics
- State:
- Created a year ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
bug: [iOS] Capacitor Camera API crashes the app when it ...
bug: [iOS] Capacitor Camera API crashes the app when it should open the camera to take a photo (iphone11 | ios14.2) #3865.
Read more >iOS Troubleshooting Guide | Capacitor Documentation
On iOS, this can happen if Capacitor doesn't find the plugins or can't inject its code into the WebView. First of all, make...
Read more >Error loading image from Capacitor Camera - Ionic Forum
When trying to grab a photo from my iOS simulator camera roll, I am getting this error: Error: Uncaught (in promise): Error: Error...
Read more >@capacitor/camera - npm
On Android and iOS, saving to the gallery can fail if the user didn't grant the required permissions. On Web there is no...
Read more >ionic: exception 'NSInternalInconsistencyException' with ...
I migrate my ionic app from cordova to capacitor. When I test camera(with cordova plugin) I have this bug. So I test also...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
There is a bug in your test app, I’ve sent a PR fixing it https://github.com/BechirAhmed/ionic-upload/pull/1 But even after the fix I can’t reproduce the issue (the error before fixing the bug was different, so I don’t think it’s the same problem) Can you provide more information about how are you testing? using live reload or loading local assets? real device or simulator? iOS version?
Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Capacitor, please create a new issue and ensure the template is fully filled out.