-
Notifications
You must be signed in to change notification settings - Fork 170
Android 7+ problem in save cropped image #72
Comments
Same problem here!! |
Same issue. |
@brunosoaresds same issue here, did you fixed it somehow? |
No, unfortunatelly i didn't fix it yet. Actually in my app i have disabled crop in android 7+. I hope someone fix it asap. |
Hi, I have been trying to solve it for a couple of days and best way I found to avoid the error is this: private cropDevice(options: ImageTransformationOptions) {
return (cameraResult: Observable<string>) => cameraResult.pipe(
switchMap(url => this.crop(url, {
quality: 100,
targetWidth: options.crop.width,
targetHeight: options.crop.height,
destinationType: DestinationType.DATA_URL,
encodingType: EncodingType.JPEG
})),
// USE Cordova File Plugin to read file
switchMap(url => new Promise((resolve, reject) =>
(window as any).resolveLocalFileSystemURL(
url,
(file: any) => file.file((data: File) => resolve(data)),
(err: Error) => reject(err)))),
// USE browser FileReader to convert it to base64 stirng
switchMap((file: File) => new Promise((resolve, reject) => {
const reader = new FileReader();
reader.onload = (event: any) => resolve(event.target.result);
reader.onerror = err => reject(err);
reader.readAsDataURL(file);
}))
);
} It seems that saved crop image is being saved in local fs and then in app browser is not capable of querying it. So the solution is to use Cordova File Plugin and you are done. It's working from Android 5.0.1 to Android 9. I didn't try older versions. |
@draco1989 did you have tested using the Cordova File Plugin readAsDataURL method instead of using the FileReader? maybe the readAsDataURL can accept the file:// archive too. |
Weirdo, but installing https://github.com/apache/cordova-plugin-file started to work as expected D: Permissions, perhaps? I'm going to upload a working sample for you guys. Thanks everybody! 👯♀️ |
🖼️ Check this out: https://github.com/lfreneda/ionic-crop-image-demo |
@brunosoaresds That piece of code is just a partial of my code, and I have more steps between, but yes, you can use that method to get base64. |
Maybe you need to use cordova-plugin-android-permissions to check and request for WRITE_EXTERNAL_STORAGE permission before selecting image.
|
Hi all,
I'm facing a problem of FILE NOT FOUND when i use this library in android 7+. After search, i see that api 24 have changed the access to file:// and maybe because of that this problem is occurring. When i set the targetSdk to version 23 everything works fine, but google play only accepts now apps with targetSdk 26+. Unfortunately i have not found a solution for this problem, can anyone help?
Related problem:
Best
The text was updated successfully, but these errors were encountered: