首页 文章

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

提问于
浏览
0

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

是否可以查看/显示任何 memory stream/byte stream 哪个mime类型,如 .png/jpeg etc . , . 来自api无论我在离子inapp浏览器中收到什么?只有流数据?

还是仅仅是为了 open the url's ?它支持内存流数据吗?

2 回答

  • 0

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

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

    INAPP BROWSER也将处理此页面

  • 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
      });
    

相关问题