离子5-文件API不起作用-file.readAsArrayBuffer始终返回null

问题描述

我正在尝试读取文件(图像,PDF等),但Ionic Native File API无法正常工作。遵循代码

import { Entry,FileEntry,File } from '@ionic-native/file/ngx';
import { FilePath } from '@ionic-native/file-path/ngx';
import { FileChooser } from '@ionic-native/file-chooser/ngx';

export class DocumentCreationPage extends implements OnInit,OnDestroy {
  constructor(
        private androidPermissions: AndroidPermissions,private fileChooser: FileChooser,private filePath: FilePath,private file: File
      ) {}

    async openFiles() {
        this.fileChooser
        .open()
        .then(contentPath => {
          const that = this;
          this.filePath.resolveNativePath(contentPath).then(uri => {
        
            const lastSeparator = uri.lastIndexOf('/');
            const fileName = uri.substr(lastSeparator + 1);
            const sysPath = uri.substr(0,lastSeparator);

            that.file.readAsArrayBuffer(sysPath,fileName).then(buff => {
                // buff is always null
                const blob = new Blob([new Uint8Array(buff)],{ type: 'image/jpg' });
            });
          });
        });
    }
}

我可以打开文件选择器组件,选择文件,并获取名称,大小和完整位置,但是我无法读取文件内容。我不知道是否需要其他任何步骤或配置来解决此问题。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)