Closed indraraj26 closed 4 years ago
I can't reproduce, can you provide a sample app? Also, what's the Android version of the device?
According to OP the device is an Xiaomi Redmi 4A.
Probably not related, but we've seen a similar issue with OOM killing the app when taking photos. This is on iOS though, and not using the Camera plugin, so probably not related. But could be if this issue turns out to be OOM-related too. Just wanted to make a short note about it here, in case it helps.
A suggestion - use CameraResultType.Uri
along with lowering the quality
(which you're already doing) instead of base 64. With smartphones able to take incredibly high-quality photos these days, I'm not surprised this could happen. Using base64 format means a huge amount of data is loaded into memory.
@jcesarmobile I have added you in private repo (github) please check invite link and as well as apk which is in repo.
Reproduce:
Device: Xiaomi Redmi 4A Android Version: 7.1.2
Edit: Hi @dotNetkow , I have tried with FILE_URI with cordova due to new version of webview which serve our app with localhost:// or ionic:// i get 404 file not found in iOS when i convert file with base64 ionic native.
Method with FileReader and base64: https://github.com/indraraj26/camera-test-ios/blob/master/src/app/home/home.page.ts Repo: https://github.com/ionic-team/cordova-plugin-ionic-webview/issues/500
Thank you.
@indraraj26 I agree with others, avoid base64.
We're doing something like this, perhaps it helps:
let takePhoto = function() {
return CapacitorPlugins.Camera.getPhoto(cameraOptions)
.then((cameraPhoto) => {
return cameraPhoto.path; // `path` requires that result type is `CAMERA_RESULT_TYPE.Uri`
})
.catch((error) => {
throw error;
});
};
let convertBlob = function(fileUrl) {
// converting Capacitor file URL to Blob,
// from 'file://…' to 'http://localhost/_capacitor_file_…'
let fileUrlHttp = Capacitor.convertFileSrc(fileUrl);
return fetch(fileUrlHttp)
.catch((err) => {
throw new Error(`Photo fetch failed due to lack of response ('${err}')`);
})
.then((response) => {
if (response.ok) {
return response.blob();
} else {
throw new Error(`Photo fetch failed ('${response.statusText}')`);
}
});
};
// usage example (simple)
takePhoto().then((fileUrl) => {
return convertToBlob(fileUrl);
});
Thank you @sandstrom, Let me test with your code.
The app where you added me didn't build because of some missing variable.
Anyway, I tried once again calling getPhoto with your options and I can't make the app crash. But as it's been mentioned, base64 consumes a lot of memory and could cause this issue, we recommend using CameraResultType.Uri
instead. it returns two paths, path
is the native file path that you can use in native plugins, and webPath
, it's a path that the webview understands, so can be used as src on images, on fetch/XHR, etc.
I'll close since I was unable to reproduce.
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.
Bug Report
Capacitor Version
npx cap doctor
output:Affected Platform(s)
Current Behavior
Steps:
Youtube Video : https://www.youtube.com/watch?v=7N_DgvDtlYY&feature=youtu.be
Expected Behavior
It should not crash.
Sample Code or Sample Application Repo
Code that i am using for camera.
Reproduction Steps
Other Technical Details
npm --version
output: 6.9.0node --version
output: v10.16.3pod --version
output (iOS issues only):Other Information
Crash Log: