Skip to content

v2.3.0 - Upload filename for Buffer and stream

Choose a tag to compare

@drdmitry drdmitry released this 30 Oct 02:13
· 3 commits to main since this release

✨ Highlights

🏷️ Name your Buffer and stream uploads

FilesAPI.upload() takes a new filename option. A Buffer or stream used to be stored as file, and converters that carry the input name into the result showed it: a PDF from convert.website_to_pdf was titled "file" when the HTML had no <title>, and the result downloaded as file.pdf.

const fileId = await client.files.upload(Buffer.from(html, 'utf-8'), {
  filename: 'Invoice 42',
});

For a path, filename replaces the file's basename. Non-ASCII names are kept as they are.

🔧 convert() takes a name for streams too

{ stream, filename? } joins { buffer, filename? } as convert() input.

🐛 Fixed

convert({ input: { buffer, filename } }) dropped filename, so the upload was named file even though the type accepted a name.

💡 Good to know

  • The result file is named after the full upload name plus the new extension: Invoice 42.html gives Invoice 42.html.pdf, Invoice 42 gives Invoice 42.pdf.
  • For convert.website_to_pdf, the page's own <title> takes priority over the upload name for the PDF title.

🧪 Tests

101 tests passing (8 new: Buffer, stream and path names, the file fallback, non-ASCII names, header-safe quoting, and convert() passing the name through).

📦 Install

npm install conversiontools@2.3.0