UNPKG

@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.

63 lines 1.87 kB
import { type UploadFileOptions } from './upload-file.js'; import type { ServiceResponse, UploadImagePreset } from '@nexim/upload-types'; export type UploadImageOptions = Omit<UploadFileOptions, 'path'> & { path: string; preset: UploadImagePreset; throwOnClientOptimizationError?: boolean; }; /** * Uploads an image to the server, optimizing it first. * * @param file - The image file to upload. * @param options - The upload options. * @returns A promise that resolves to the server response. * * @example * ```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); * ``` */ export declare function uploadImage(file: Blob, options: UploadImageOptions): Promise<ServiceResponse<{ files: string[]; }>>; /** * Optimizes an image on the client side. * * @param rawImage - The raw image blob. * @param clientConfig - The client-side optimization configuration. * @returns A promise that resolves to the optimized image blob. * * @example * ```typescript * const rawImage = new Blob(['...'], { type: 'image/jpeg' }); * const config = { * width: 100, * height: 100, * quality: 90 * }; * * const optimizedBlob = await optimizeImage(rawImage, config); * ``` */ export declare function optimizeImage(rawImage: Blob, clientConfig: UploadImagePreset['client']): Promise<Blob>; //# sourceMappingURL=upload-image.d.ts.map