android - Capacitor - open file without caching it locally - Stack Overflow

I've got the following bit of code that works for opening a base64 file by first caching it, and t

I've got the following bit of code that works for opening a base64 file by first caching it, and then opening it. I'm wondering if there is a way to preview it without caching it locally.

import { Filesystem, Directory } from '@capacitor/filesystem';
import { FileOpener } from '@capacitor-community/file-opener';

export type PreviewFileOptions = {
  fileName: string;
  contentType: string;
  base64Str: string;
};

async function previewFile(args: PreviewFileOptions): Promise<void> {
  try {
    const response = await Filesystem.writeFile({
      path: args.fileName,
      data: args.base64Str,
      directory: Directory.Cache,
      recursive: true,
    });
    await FileOpener.open({
      filePath: response.uri,
      contentType: args.contentType,
      openWithDefault: true,
    });
  } catch (e) {
    // handle error
  }
}

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742346968a4426738.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信