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.

52 lines 1.9 kB
import type { MaybePromise } from '@alwatr/type-helper'; /** * Creates and triggers a virtual file input element to handle file selection. * This utility creates a temporary file input element, attaches event handlers, * and removes itself after use. * * Features: * - Creates a hidden file input element * - Handles file selection through browser's native interface * - Automatically cleans up after selection * - Supports async callbacks for processing selected files * - Filters files based on accept parameter (MIME types) * * @param accept - Comma-separated list of allowed file types (e.g., 'image/*', '.pdf', 'image/jpeg,image/png') * @param callback - Function to handle the selected file. Can be async for long-running operations. * * @example * ```typescript * // Example 1: Pick an image and upload it using uploadImage * import { pickAndProcessFile, uploadImage } from '@nexim/upload-sdk'; * * pickAndProcessFile('image/*', async (file) => { * await uploadImage(file, { * path: 'images/user-avatar', * auth: { id: '...', token: '...' }, * description: 'User Avatar', * apiEndpoint: 'https://api.example.com/upload', * preset: { * client: { width: 512, height: 512, quality: 90 }, * // ... * }, * }); * }); * ``` * * @example * ```typescript * // Example 2: Pick a PDF and upload it using uploadFile * import { pickAndProcessFile, uploadFile } from '@nexim/upload-sdk'; * * pickAndProcessFile('.pdf', async (file) => { * await uploadFile(file, { * path: 'documents/report.pdf', * auth: { id: '...', token: '...' }, * description: 'Monthly Report', * apiEndpoint: 'https://api.example.com/upload', * }); * }); * ``` */ export declare function pickAndProcessFile(accept: string, callback: (file: File) => MaybePromise<void>): void; //# sourceMappingURL=virtual-file-input.d.ts.map