文件未找到错误使用离子本机文件插件

问题描述:

我想实现一个简单的用户注册,用户可以选择上传配置文件图像。文件未找到错误使用离子本机文件插件

我正在使用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的真实设备上测试。

+0

有时回来时,我试图做同样的,我得知道,高速缓存目录不能读取由于权限问题,然后我切换到externalDataDirectory – Gandhi

+0

它看起来并不像,因为作物权限问题插件能够写入缓存目录。我通过使用文件管理器检查了应用程序的缓存目录,我可以在那里看到图像。 –

+0

您是否可以在datadirectory中尝试一次以隔离此问题? – Gandhi

尝试

this.file.cacheDirectory.replace(/^file:\/\//, '');