我无法从离子应用的缓存目录中显示图像文件。 我的过程是这样的:
1)它从缓存目录中的电话存储中复制文件(复制功能很好(我得到了返回的条目)
copyFile(uriFile,targetPath,newName){
var deferred = new Promise<any>(resolve => {
this.file.resolveLocalFilesystemUrl(uriFile).then(fileEntry =>
{
this.filePath.resolveNativePath(fileEntry.nativeURL).then(
filePath =>
{
if(newName == null)
newName = filePath.split('/').pop();
else if(newName == "")
newName = filePath.split('/').pop();
this.file.resolveDirectoryUrl(targetPath).then(dirEntry => {
fileEntry.copyTo(dirEntry,newName, entry =>{
resolve(entry);
}, function(error){
resolve("ERROR");
});
});
},
error => {
resolve("ERROR");
});
})
.catch(error => {
resolve("ERROR");
})
});
2)接下来,使用entry.nativeURL
设置objet属性。
getRepertoireTemporaire()
{
if(this.rootScope.mobileType == "IOS")
return this.file.tempDirectory;
else
return this.file.cacheDirectory;
}
var uriFile = "";
if(this.rootScope.mobileType == "IOS")
uriFile = this.file.syncedDataDirectory;
else
uriFile = this.file.externalRootDirectory;
uriFile += fileName;
this.techniqueMetier.copyFile(uriFile, this.techniqueMetier.getRepertoireTemporaire(),null).then(entry =>
{
this.info.path = entry.nativeURL;
if(name != "ERROR")
this.info.displayImage = true;
else
this.info.displayImage = false;
this.content.scrollToBottom(500);
}).catch(err =>
{
alert(err);
});
3)然后,我在视图上显示文件,例如:
<img *ngIf="info.displayImage" style="width: 100%;" [src]="info.path">
我使用的是cordova-plugin-ionic-webview也许是因为我是我的应用程序的早期版本(ionic v1),此过程有效=(
有人知道吗? 问候