@nexim/upload-sdk
Version:
TypeScript SDK for seamless integration with Nexim Media Upload Service. It provides state machine-based upload handling, progress tracking, and type-safe API for image optimization and file uploads.
44 lines (30 loc) • 1.33 kB
Markdown
[@nexim/upload-sdk](../README.md) / uploadFile
> **uploadFile**(`file`: `Blob`, `options`: [`UploadFileOptions`](../type-aliases/UploadFileOptions.md)): `Promise`\<`ServiceResponse`\<\{ `files`: `string`[]; \}\>\>
Uploads a file to the server.
| Parameter | Type | Description |
| --------- | ----------------------------------------------------------- | ------------------- |
| `file` | `Blob` | The file to upload. |
| `options` | [`UploadFileOptions`](../type-aliases/UploadFileOptions.md) | The upload options. |
`Promise`\<`ServiceResponse`\<\{ `files`: `string`[]; \}\>\>
A promise that resolves to the server response.
```typescript
import { uploadFile } from '@nexim/upload-sdk';
// Usually used inside a file picker callback
const file = new File(['content'], 'test.txt', { type: 'text/plain' });
const options = {
path: 'files/test.txt',
auth: { id: 'user', token: 'token' },
description: 'Test file',
apiEndpoint: 'https://api.example.com/upload',
};
try {
const response = await uploadFile(file, options);
console.log('Upload success:', response);
} catch (err) {
console.error('Upload failed:', err);
}
```