From 2507fbdad0ab2cd187984adc17ee75cecd0fb94f Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Wed, 19 Feb 2025 05:33:07 +0000 Subject: [PATCH] chore(internal): codegen related update --- README.md | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/README.md b/README.md index 7e6295f8..c361685c 100644 --- a/README.md +++ b/README.md @@ -57,6 +57,42 @@ main(); Documentation for each method, request param, and response field are available in docstrings and will appear on hover in most modern editors. +## File uploads + +Request parameters that correspond to file uploads can be passed in many different forms: + +- `File` (or an object with the same structure) +- a `fetch` `Response` (or an object with the same structure) +- an `fs.ReadStream` +- the return value of our `toFile` helper + +```ts +import fs from 'fs'; +import fetch from 'node-fetch'; +import Hyperspell, { toFile } from 'hyperspell'; + +const client = new Hyperspell(); + +// If you have access to Node `fs` we recommend using `fs.createReadStream()`: +await client.documents.upload({ collection: 'collection', file: fs.createReadStream('/path/to/file') }); + +// Or if you have the web `File` API you can pass a `File` instance: +await client.documents.upload({ collection: 'collection', file: new File(['my bytes'], 'file') }); + +// You can also pass a `fetch` `Response`: +await client.documents.upload({ collection: 'collection', file: await fetch('https://somesite/file') }); + +// Finally, if none of the above are convenient, you can use our `toFile` helper: +await client.documents.upload({ + collection: 'collection', + file: await toFile(Buffer.from('my bytes'), 'file'), +}); +await client.documents.upload({ + collection: 'collection', + file: await toFile(new Uint8Array([0, 1, 2]), 'file'), +}); +``` + ## Handling errors When the library is unable to connect to the API,