我正在为android,ios和windows开发一个应用程序。其中一个要求是能够下载存储在离子应用程序的assets文件夹中的pdf。我正在使用此插件https://ionicframework.com/docs/native/file-opener/。我按照文档执行此代码。
this.fileOpener.open(‘assets/pdf-test.pdf’, ‘application/pdf’)
.then(() => console.log(‘File is opened’))
.catch(e => console.log(‘Error openening file’, e));
但是我收到以下错误
“找不到档案”
请帮忙
答案 0 :(得分:0)
assetsfolder only works in your app. What you are telling these others apps to do is to read help_doc.pdf out of their assets, and they do not have such a file.
try this code , but if not work , some time browser not support open pdf , then go must go with plugin fileOpener2
var location = cordova.file.applicationDirectory +"www/assets/MobiMedPrivacyPolicy.pdf";
window.resolveLocalFileSystemURL(location, function(fileEntry) {
window.resolveLocalFileSystemURL(cordova.file.externalRootDirectory + '/Download/', function(dirEntry) {
fileEntry.copyTo(dirEntry, "MobiMedPrivacyPolicy.pdf", function(newFileEntry) {
window.open(newFileEntry.nativeURL, '_blank', 'location=no');
});
});
},function(error)
{
console.log(error)
});