# @salmonui/inputs/file-upload/xhr API reference

> 4 exported symbols of @salmonui/inputs/file-upload/xhr: 1 function, 1 class and 2 interfaces.

Canonical: https://salmonui.dev/docs/reference/inputs/file-upload-xhr

```ts
import { … } from '@salmonui/inputs/file-upload/xhr';
```

## Functions

### createXhrUploader

Kind: function

Page: https://salmonui.dev/docs/reference/inputs/file-upload-xhr/createXhrUploader

```ts
function createXhrUploader(options: XhrUploaderOptions): (file: File, context: UploadContext) => Promise<XhrUploadResult>;
```

Creates an `upload` transport: `<FileUpload upload={createXhrUploader({ url:
'/api/files' })} />`. Resolves with `{ status, body }` on 2xx, rejects with
an `XhrUploadError` otherwise and with an `AbortError` when canceled.

## Classes

### XhrUploadError

Kind: class

Page: https://salmonui.dev/docs/reference/inputs/file-upload-xhr/XhrUploadError

```ts
class XhrUploadError extends Error {
    readonly status: number;
    readonly body: string;
    constructor(status: number, body: string);
}
```

Rejection of a non-2xx response, or of a network failure (`status` 0).

Members (2):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `status` | `readonly status: number;` |  |  |
| `body` | `readonly body: string;` |  |  |

## Interfaces

### XhrUploadResult

Kind: interface

Page: https://salmonui.dev/docs/reference/inputs/file-upload-xhr/XhrUploadResult

```ts
interface XhrUploadResult {
    readonly status: number;
    readonly body: string;
}
```

What the transport resolves with: the response status and body text.

Members (2):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `status` | `readonly status: number;` |  |  |
| `body` | `readonly body: string;` |  |  |

### XhrUploaderOptions

Kind: interface

Page: https://salmonui.dev/docs/reference/inputs/file-upload-xhr/XhrUploaderOptions

```ts
interface XhrUploaderOptions {
    readonly url: string | ((file: File) => string);
    readonly method?: string | undefined;
    readonly headers?: Readonly<Record<string, string>> | ((file: File) => Readonly<Record<string, string>>) | undefined;
    readonly fieldName?: string | undefined;
    readonly data?: Readonly<Record<string, string>> | ((file: File) => Readonly<Record<string, string>>) | undefined;
    readonly withCredentials?: boolean | undefined;
}
```

Members (6):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `url` | `readonly url: string \| ((file: File) => string);` |  | Target URL, or a function of the file. |
| `method` | `readonly method?: string \| undefined;` | optional | Default `'POST'`. |
| `headers` | `readonly headers?: Readonly<Record<string, string>> \| ((file: File) => Readonly<Record<string, string>>) \| undefined;` | optional | Request headers, or a function of the file (auth tokens, CSRF). |
| `fieldName` | `readonly fieldName?: string \| undefined;` | optional | Multipart field name of the file. Default `'file'`. |
| `data` | `readonly data?: Readonly<Record<string, string>> \| ((file: File) => Readonly<Record<string, string>>) \| undefined;` | optional | Extra multipart fields sent with each file. |
| `withCredentials` | `readonly withCredentials?: boolean \| undefined;` | optional | Sends cookies cross-origin. Default `false`. |
