1
我想實現一個簡單的用戶註冊,用戶可以選擇上傳配置文件圖像。文件未找到錯誤使用離子本機文件插件
我正在使用Ionic本地作物插件來裁剪圖像。這將返回一個URI,我將使用該URI使用本機文件插件從緩存目錄讀取文件。現在的問題是file.readAsDataURL()
返回文件未找到錯誤。
這裏是我的代碼:
addFromGallery(){
this.camera.getPicture(this.galleryOptions)
.then((fileUri) => {
// Modify fileUri format, may not always be necessary
fileUri = 'file://' + fileUri;
/* Using cordova-plugin-crop starts here */
return this.crop.crop(fileUri, { quality: 100 });
}).then((path) => {
this.file.readAsDataURL(this.file.cacheDirectory, "a.txt")
.then(function (success) {
console.log("SUCESS", success);
// success
}, function (error) {
console.log('ERROR', error);
// error
});
})
}
我已經安慰this.file.cacheDirectory
並返回在其中a.txt中的位置(文件的正確路徑:///存儲/模擬/ 0 /安卓/數據/ COM。 ionicframework.myapp191974/cache /)file.readAsDataURL()
找不到它。
我在運行Android Nougat的真實設備上測試。
有時回來時,我試圖做同樣的,我得知道,高速緩存目錄不能讀取由於權限問題,然後我切換到externalDataDirectory – Gandhi
它看起來並不像,因爲作物權限問題插件能夠寫入緩存目錄。我通過使用文件管理器檢查了應用程序的緩存目錄,我可以在那裏看到圖像。 –
您是否可以在datadirectory中嘗試一次以隔離此問題? – Gandhi