Error: Uncaught (in promise): [object Object] with Ionic native file plugin

Error: Uncaught (in promise): [object Object] with Ionic native file plugin

我需要使用 blob 创建一个 pdf,我已经关注 this blog。但它不起作用。你能告诉我为什么吗?

注意:此行发出错误 const fileEntry = await。这是在 android device 上。在浏览器上,它工作正常(即 this.pdfObj.download();)。

  constructor(
    private file: File,
    private platform: Platform,
    private fileOpener: FileOpener,
  ) {
  }

downloadReport() {
    this.createPdf();
    if (this.platform.is('cordova')) {
      try {
        this.pdfObj.getBuffer(async (buffer) => {
          var utf8=new Uint8Array(buffer);
          var binaryArray=utf8.buffer;
          var blob = new Blob([binaryArray], { type: 'application/pdf' });

          const fileEntry = await this.file.writeFile(this.file.dataDirectory, 'myletter.pdf', blob, { replace: true });
          this.fileOpener.open(this.file.dataDirectory + 'myletter.pdf', 'application/pdf');
        });
      }
      catch (err) {
        console.log(err);
      }

    } else {
      // On a browser simply use download!
      this.pdfObj.download();
    }
  }  



createPdf() {
    var docDefinition = {
      content: [
        { text: 'REMINDER', style: 'header' },
        { text: new Date().toTimeString(), alignment: 'right' },

        { text: 'From', style: 'subheader' }, { text: 'from' },

        { text: 'To', style: 'subheader' }, 'To',

        { text: 'Sam lokuge', style: 'story', margin: [0, 20, 0, 20] },

        {
          ul: [
            'Bacon',
            'Rips',
            'BBQ',
          ]
        }
      ],
      styles: {
        header: {
          fontSize: 18,
          bold: true,
        },
        subheader: {
          fontSize: 14,
          bold: true,
          margin: [0, 15, 0, 0]
        },
        story: {
          italic: true,
          alignment: 'center',
          width: '50%',
        }
      }
    }
    this.pdfObj = pdfMake.createPdf(docDefinition);
  }

这是错误:

 core.js:1350 ERROR Error: Uncaught (in promise): [object Object]
        at c (polyfills.js:3)
        at polyfills.js:3
        at rejected (assessment-report.module.ts:13)
        at t.invoke (polyfills.js:3)
        at Object.onInvoke (core.js:4629)
        at t.invoke (polyfills.js:3)
        at r.run (polyfills.js:3)
        at polyfills.js:3
        at t.invokeTask (polyfills.js:3)
        at Object.onInvokeTask (core.js:4620)

我在这里发现了问题。那是由于这条路径 this.file.dataDirectory。但是错误信息并没有明确提到这一点。所以花了很多时间来确定问题。最后,我改变了路径,然后没有问题。我已经使用了这条路径 this.file.externalApplicationStorageDirectory,现在它工作正常。