Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down