Error during FilesApi.uploadFile()

Offen
#556 0 Kommentare 0 Reaktionen 1 zugewiesene Person Auf GitHub ansehen

@sangeet-joy-tw arbeitet bereits daran.

Seit 12.2.2024.

Bewertung

Dieses Issue wurde noch nicht bewertet.

Beschreibung

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

Vorherrschende Sprache
TypeScript
Sterne
264
Forks
177
Ø Merge
10 Std. 5 Min.
Gemergte PRs (30 T.)
5

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus XeroAPI/xero-node

Alle Issues in XeroAPI/xero-node

Ähnliche Issues

Weitere Issues zu TypeScript

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.