Error during FilesApi.uploadFile()

Aperta
#556 0 commenti 0 reazioni 1 assegnatario Vedi su GitHub

@sangeet-joy-tw ci sta già lavorando.

Dal 12/2/2024.

Valutazione

Questa issue non è ancora stata valutata.

Descrizione

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

Lingua principale
TypeScript
Stelle
264
Fork
177
Merge medio
10h 5m
PR unite (30g)
5

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di XeroAPI/xero-node

Tutte le issue di XeroAPI/xero-node

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.