Ionic 5 capacitor/angular 从外部 url 预览文件
Ionic 5 capacitor/angular preview files from external url's
我已经尝试使用 previewanyfile cordova 插件在 Ionic 5 应用程序中打开来自外部 url 的文件。它适用于 android 但在 IOS 上我注意到有时它没有 preview/open PDF 文件。只是一个带有文件名的灰色屏幕。但奇怪的是,一些 PDF 文件打开了。
file preview screen
previewProductDocument(url: string) {
const loading = await this.loadingController.create({
message: 'Loading document...',
});
loading.present().then(() => {
this.previewAnyFile.preview(url).then((res) => {
loading.dismiss();
}).catch((err) => {
loading.dismiss();
this.presentToast('Error previewing the document try later', 'danger');
});
});
}
这是我用过的插件
https://ionicframework.com/docs/native/preview-any-file
电容版本 "@capacitor/core": "^2.2.0",
仅在 IOS 模拟器 + 真实 IOS 设备上注意到此行为。
知道这里发生了什么吗?
Special character (%2F)中的link是问题的原因。
速战速决;更改 link 或在处理前进行消毒。
在这种情况下 url.replace('%2F', '/')
应该有效。
但是,另一个 link 可能包含不同的字符。虽然不能 100% 确定,但值得一试 decodeURI,即 decodeURI(url)
.
我已经尝试使用 previewanyfile cordova 插件在 Ionic 5 应用程序中打开来自外部 url 的文件。它适用于 android 但在 IOS 上我注意到有时它没有 preview/open PDF 文件。只是一个带有文件名的灰色屏幕。但奇怪的是,一些 PDF 文件打开了。 file preview screen
previewProductDocument(url: string) {
const loading = await this.loadingController.create({
message: 'Loading document...',
});
loading.present().then(() => {
this.previewAnyFile.preview(url).then((res) => {
loading.dismiss();
}).catch((err) => {
loading.dismiss();
this.presentToast('Error previewing the document try later', 'danger');
});
});
}
这是我用过的插件 https://ionicframework.com/docs/native/preview-any-file
电容版本 "@capacitor/core": "^2.2.0",
仅在 IOS 模拟器 + 真实 IOS 设备上注意到此行为。 知道这里发生了什么吗?
Special character (%2F)中的link是问题的原因。
速战速决;更改 link 或在处理前进行消毒。
在这种情况下 url.replace('%2F', '/')
应该有效。
但是,另一个 link 可能包含不同的字符。虽然不能 100% 确定,但值得一试 decodeURI,即 decodeURI(url)
.