@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.
47 lines (33 loc) • 1.39 kB
Markdown
[@nexim/upload-sdk](../README.md) / uploadImage
> **uploadImage**(`file`: `Blob`, `options`: [`UploadImageOptions`](../type-aliases/UploadImageOptions.md)): `Promise`\<`ServiceResponse`\<\{ `files`: `string`[]; \}\>\>
Uploads an image to the server, optimizing it first.
| Parameter | Type | Description |
| --------- | ------------------------------------------------------------- | ------------------------- |
| `file` | `Blob` | The image file to upload. |
| `options` | [`UploadImageOptions`](../type-aliases/UploadImageOptions.md) | The upload options. |
`Promise`\<`ServiceResponse`\<\{ `files`: `string`[]; \}\>\>
A promise that resolves to the server response.
```typescript
import { uploadImage } from '@nexim/upload-sdk';
// Usually used inside a file picker callback
const file = new File(['image data'], 'photo.jpg', { type: 'image/jpeg' });
const options = {
path: 'images/photo',
auth: { id: 'user', token: 'token' },
description: 'User photo',
apiEndpoint: 'https://api.example.com/upload',
preset: {
client: {
width: 800,
height: -1,
quality: 80
},
// ... other preset options
},
};
await uploadImage(file, options);
```