【问题标题】:How to open FileURL in IONIC 4?如何在 IONIC 4 中打开 FileURL?
【发布时间】:2019-10-16 15:19:49
【问题描述】:
 this.api.getapi().subscribe((response) => {
      let file = new Blob([response], { type: 'application/pdf' });
      var fileURL = URL.createObjectURL(file);
        var ref = window.open(fileURL, '_self', 'location=yes');
    })

Window.open 正在显示一个空白屏幕,标题上带有 URL(blob 链接)。 它适用于浏览器,但不适用于 ANDROID 和 IOS

响应是pdf。

我需要在我的应用程序 ionic 4 中打开文件 url(blob:http://localhost/6a9c5e03-8771-402c-..)。

【问题讨论】:

  • 您只想打开 pdf 或任何类型的文件吗?为什么不打开应用内浏览器显示 pdf 文件?
  • 应用内浏览器未打开 blob URL 链接。我不想下载pdf。

标签: angular cordova ionic-framework ionic4


【解决方案1】:
   Import { FileOpener } from '@ionic-native/file-opener/ngx';

 constructor(private fileOpener: FileOpener) { }
 this.fileOpener.open('path/to/file.pdf', 'application/pdf')
 .then(() => console.log('File is opened'))
 .catch(e => console.log('Error opening file', e));

尝试使用Cordova file opener

【讨论】:

  • 如何创建path/to/file.pdf
  • path/to/file.pdf 是你的文件目录。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-04-13
  • 1970-01-01
  • 1970-01-01
  • 2020-05-12
  • 2019-12-07
  • 2020-10-05
  • 1970-01-01
相关资源
最近更新 更多