Ionic 3 inapp浏览器打开字节数组

时间:2018-04-17 13:05:14

标签: angular cordova ionic-framework

我有一个与离子3 /角4混合移动应用程序有关的问题。

是否可以查看/显示任何内存流/字节流,无论哪种mime类型,如 .png / jpeg等。来自api无论我在离子inapp浏览器中收到什么? 只有流数据?

或者只是打算打开网址?它是否支持内存流数据?

2 个答案:

答案 0 :(得分:0)

您可以创建外部页面,假设您已创建了一个页面https://yourdomain.com/loadpic/ {id}。

然后,您可以使用此页面传递变量ID或任何标识符并显示图像或任何内容,

INAPP BROWSER也将处理此页面

答案 1 :(得分:0)

如果应用内浏览器不是这里的硬性要求,那么答案是肯定的,您可以通过离子/角度混合移动应用中的字节数组/流来查看/显示各种mime类型。我建议使用File Opener cordova插件来帮助查看/打开,这有一个很好的ionic native wrapper

你可能会在这里处理JS Blob。您将要将Blob作为文件保存到设备,然后使用File Opener打开/查看它。如果您的混合应用程序也作为Web应用程序托管,那么您在该方案中需要特定于Web的方法。原生方面的一些示例代码如下(假设不需要Web)。它使用File / File Opener Cordova插件。

var blob = new Blob([res], { type: 'application/pdf' });

//Determine a native file path to save to
let filePath = (this.appConfig.isNativeAndroid) ? this.file.externalRootDirectory : this.file.cacheDirectory;

//Write the file
this.file.writeFile(filePath, fileName, blob, { replace: true }).then((fileEntry: FileEntry) => {

  console.log("File created!");

  //Open with File Opener plugin
  this.fileOpener.open(fileEntry.toURL(), data.type)
    .then(() => console.log('File is opened'))
    .catch(err => console.error('Error openening file: ' + err));
})
  .catch((err) => {
    console.error("Error creating file: " + err);
    throw err;  //Rethrow - will be caught by caller
  });
相关问题