@health-ecosystem/file-upload
Version:
File upload library for Health Ecosystem applications with improved Next.js 15+ compatibility
119 lines • 3.17 kB
TypeScript
/**
* File Upload Client
* Production-ready client for Health Ecosystem file uploads
*/
import { FileUploadConfig, UploadOptions, UploadResult, FileMetadata, PreviewOptions } from './types';
export declare class FileUploadClient {
private client;
private config;
private cancelTokens;
constructor(config: FileUploadConfig);
/**
* Upload a single file
*/
uploadFile(file: File, options?: UploadOptions, callbacks?: {
onProgress?: (progress: number) => void;
}): Promise<UploadResult>;
/**
* Upload multiple files
*/
uploadFiles(files: File[], options: UploadOptions): Promise<UploadResult[]>;
/**
* Upload file from URL
* Downloads the file from the provided URL and uploads it to the server
*/
uploadFromUrl(url: string, options: UploadOptions & {
filename?: string;
}): Promise<UploadResult>;
/**
* Get file metadata
*/
getFileMetadata(fileId: string): Promise<FileMetadata>;
/**
* Get download URL for a file
*/
getDownloadUrl(fileId: string): string;
/**
* Get thumbnail URL for an image
*/
getThumbnailUrl(fileId: string): string;
/**
* Get preview URL for a file with optional transformations
* @param previewUrl The preview URL from the file response
* @param options Optional transformation parameters
* @returns Full URL to the preview
*/
getPreviewUrl(previewUrl: string, options?: PreviewOptions): string;
/**
* Delete a file
*/
deleteFile(fileId: string): Promise<void>;
/**
* List files with optional filters - Updated to match backend API structure
*/
listFiles(options?: {
category?: string;
entityType?: string;
entityId?: string;
isPublic?: boolean;
skip?: number;
limit?: number;
}): Promise<FileMetadata[]>;
/**
* Cancel an ongoing upload
*/
cancelUpload(uploadId?: string): void;
/**
* Update authentication token
*/
updateAuthToken(token: string): void;
/**
* Validate file before upload
*/
private validateFile;
/**
* Parse upload response
*/
private parseUploadResponse;
/**
* Parse file metadata response - Updated to match backend structure
*/
private parseFileMetadata;
/**
* Create standardized upload error
*/
private createUploadError;
/**
* Handle axios errors with retry logic
*/
private handleError;
/**
* Determine if error should be retried
*/
private shouldRetry;
/**
* Generate unique upload ID
*/
private generateUploadId;
/**
* Format file size for display
*/
private formatFileSize;
/**
* Validate URL format
*/
private isValidUrl;
/**
* Extract filename from URL
*/
private extractFilenameFromUrl;
/**
* Get file extension from URL or content type
*/
private getFileExtensionFromUrl;
/**
* Check if file type is allowed
*/
private isAllowedFileType;
}
//# sourceMappingURL=FileUploadClient.d.ts.map