Reputation: 700
The plugin was working fine until recently I started facing problems with it, the code does not execute neither does it throw an error. I want to capture images from camera and send the base64
string to the server, which was easy since I could directly get the base64
of the captured image but then I used the native crop which returns the URI
of the cropped image. So now I HAVE to get the base64
of this image, but the Base64
plugin isn't working anymore. Any workaround or help is really appreciated.
Code I used:
this.base64.encodeFile(filePath).then((base64File: string) => {
console.log(base64File); // Won't execute
}, (err) => {
console.log(err); // Won't execute
});
Upvotes: 3
Views: 4719
Reputation: 153
In Android, in the build.gradle(app) file, change target SDK to targetSdkVersion 30.
Then go to your AndroidManifest.xml and add this line android:requestLegacyExternalStorage="true" in the application tag like that :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
>
<application
android:allowBackup="false"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme"
android:requestLegacyExternalStorage="true">
try to apply this solution is working for me
Upvotes: 1
Reputation: 1028
Base64 plugin is need install Device
See the repo phonegap-base64 line 11
if (device.platform == "Android")
Upvotes: 0
Reputation: 455
I spent couple of hours on the same bug. It occurred that this plugin just stopped working (it's still beta version). I made some changes in my code and replaced Base64 plugin with File Plugin.
And then if you have filepath:
// split file path to directory and file name
let fileName = filePath.split('/').pop();
let path = filePath.substring(0, filePath.lastIndexOf("/") + 1);
this.file.readAsDataURL(path, fileName)
.then(base64File => {
console.log("here is encoded image ", base64File)
})
.catch(() => {
console.log('Error reading file');
})
Upvotes: 7