UNPKG

@stacksjs/stx

Version:

A performant UI Framework. Powered by Bun.

79 lines 2.36 kB
/** * Validate a file before upload */ export declare function validateFile(file: File, options?: Partial<UploadHandlerOptions>): FileValidationResult; /** * Upload a single file with progress tracking * * @example * ```typescript * const result = await uploadFile(file, { * endpoint: '/api/upload', * onProgress: (progress) => console.log(progress.percent + '%') * }) * ``` */ export declare function uploadFile(file: File, options: UploadHandlerOptions, onProgress?: (progress: UploadProgress) => void): Promise<UploadResult>; /** * Upload multiple files */ export declare function uploadFiles(files: File[], options: UploadHandlerOptions, onProgress?: (file: File, progress: UploadProgress) => void, onComplete?: (file: File, result: UploadResult) => void): Promise<UploadResult[]>; /** * Generate a preview data URL for an image file */ export declare function generateImagePreview(file: File, maxSize?: number): Promise<string>; /** * Generate preview for video file (first frame) */ export declare function generateVideoPreview(file: File): Promise<string>; /** * Generate client-side upload handler runtime */ export declare function generateUploadRuntime(): string; /** * STX Media - Client-Side Upload Handler * * Handle file uploads with progress tracking, validation, and preview. * * @module media/client/upload-handler */ // ============================================================================= // Types // ============================================================================= export declare interface UploadHandlerOptions { endpoint: string method?: 'POST' | 'PUT' | 'PATCH' headers?: Record<string, string> fieldName?: string maxSize?: number accept?: string[] timeout?: number withCredentials?: boolean formData?: Record<string, string> chunkSize?: number } export declare interface UploadProgress { file: File loaded: number total: number percent: number speed?: number timeRemaining?: number chunk?: number totalChunks?: number } export declare interface UploadResult { success: boolean url?: string id?: string name?: string size?: number type?: string error?: string data?: Record<string, unknown> } export declare interface FileValidationResult { valid: boolean error?: string code?: 'INVALID_TYPE' | 'FILE_TOO_LARGE' | 'FILE_TOO_SMALL' }