[英]Base64 plugin not working
該插件運行良好,直到最近我開始遇到它的問題,代碼既不執行也不拋出錯誤。 我想捕捉的圖像從相機發送base64
字符串到服務器,這很簡單,因為我可以直接拿到base64
所拍攝的圖像,但當時我使用的本地農作物,它返回的URI
裁剪圖像。 所以現在我必須得到這個圖像的base64
,但是Base64
插件不再工作了。 任何解決方法或幫助都非常感謝。 我使用的代碼:
this.base64.encodeFile(filePath).then((base64File: string) => {
console.log(base64File); // Won't execute
}, (err) => {
console.log(err); // Won't execute
});
我在同一個錯誤上花了幾個小時。 碰巧這個插件剛剛停止工作(它仍然是測試版)。 我對代碼進行了一些更改,並用 File Plugin 替換了 Base64 插件。
然后如果你有文件路徑:
// 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');
})
在 Android 中,在 build.gradle(app) 文件中,將目標 SDK 更改為 targetSdkVersion 30。
然后轉到您的 AndroidManifest.xml 並在應用程序標記中添加這一行 android:requestLegacyExternalStorage="true" ,如下所示:
<?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">
嘗試應用此解決方案對我有用
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.