@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.
55 lines • 1.47 kB
TypeScript
import type { ServiceResponse, UserAuth } from '@nexim/upload-types';
export type UploadFileOptions = {
path: string;
auth: UserAuth;
description: string;
apiEndpoint: string;
/**
* Extra headers to include in the request
*/
extraHeaders?: Record<string, string>;
/**
* Maximum number of retries for the upload request.
* @defaultValue 3
*/
maxRetries?: number;
/**
* Delay in milliseconds between retries.
* @defaultValue 2000
*/
retryDelay?: number;
};
/**
* Uploads a file to the server.
*
* @param file - The file to upload.
* @param options - The upload options.
* @returns A promise that resolves to the server response.
*
* @example
* ```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);
* }
* ```
*/
export declare function uploadFile(file: Blob, options: UploadFileOptions): Promise<ServiceResponse<{
files: string[];
}>>;
//# sourceMappingURL=upload-file.d.ts.map