Error during FilesApi.uploadFile()

オープン
#556 コメント 0 件 リアクション 0 件 担当者 1 名 GitHub で見る

@sangeet-joy-tw がすでに取り組んでいます。

2024年2月12日 から。

評価

この issue はまだ評価されていません。

説明

Due to the file size limit with accountingApi.updateInvoiceAttachmentByFileName() I am tyring to switch to using filesApi.uploadFile().

The example given in the documentation uses fs.createReadStream() to generate the body. This isn't possible to use when the file content is not stored in the file system, but is instead stored as a base64 string, but this is the same for updateInvoiceAttachmentByFileName(), which was overcome using the following:

    let buffer = Buffer.from(base64String, 'base64');
    let readStream = new Readable();
    readStream._read = () => {};
    readStream.push(buffer);
    readStream.push(null);
    const contentType = 'application/pdf';
    const options = { headers: { 'Content-Type': contentType } };
    return await XeroClient.accountingApi.updateInvoiceAttachmentByFileName(
      tenantId,
      xeroInvoiceId,
      'myfile.pdf',
      readStream,
      options
    );

This has been working fine for a long time.

If I change the updateInvoiceAttachmentByFileName() line to be:

    return await XeroClient.filesApi.uploadFile(
      tenantId,
      readStream,
      'myfile.pdf',
      contentType,
      options
    );

Then it fails with an error TypeError: source.on is not a function

If I remove the options then the request is made but it returns a 400 status code with Bad Request.

As both the updateInvoiceAttachmentByFileName and uploadFile are expecting a read stream, and I am providing the same value generated from the same PDF file, shouldn't they both accept that field? If not, how else can the read stream be generated given that the fs.ReadStream can only be generated by createReadStream()?

I also tested running uploadFile using the same file from local using createReadStream() and the file uploaded but the filename field was not used on the uploaded file.

Thanks for your help

主要言語
TypeScript
スター
264
フォーク
177
平均マージ
10時間 5分
マージ済み PR(30日)
5

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

XeroAPI/xero-node のほかの issue

XeroAPI/xero-node の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。