@ahhaohho/s3-upload-sdk
Version:
S3 + CloudFront presigned URL SDK for AhhaOhho platform
76 lines (75 loc) • 2.11 kB
TypeScript
import { S3UploadConfig, UploadOptions, UploadResult } from './types';
/**
* S3 Upload Client
* Handles file uploads to S3 using presigned URLs with CloudFront distribution
*/
export declare class S3UploadClient {
private axiosInstance;
private config;
constructor(config: S3UploadConfig);
/**
* Update auth token
*/
setAuthToken(token: string): void;
/**
* Get presigned URL from API server
*/
private getPresignedUrl;
/**
* Upload file to S3 using presigned URL
*/
private uploadToS3;
/**
* Generate filename from File or Blob
*/
private generateFilename;
/**
* Get content type from File or Blob
*/
private getContentType;
/**
* Upload a file to S3 and return the CloudFront URL
*
* @param options - Upload options
* @returns Upload result with CloudFront URL
*
* @example
* ```typescript
* const result = await client.upload({
* file: fileInput.files[0],
* folder: 'announcements',
* onProgress: (progress) => console.log(`${progress}%`)
* });
* console.log('File URL:', result.url);
* ```
*/
upload(options: UploadOptions): Promise<UploadResult>;
/**
* Upload multiple files in parallel
*
* @param files - Array of files with their options
* @returns Array of upload results
*
* @example
* ```typescript
* const results = await client.uploadMultiple([
* { file: file1, folder: 'announcements' },
* { file: file2, folder: 'announcements' }
* ]);
* const urls = results.map(r => r.url);
* ```
*/
uploadMultiple(files: UploadOptions[]): Promise<UploadResult[]>;
/**
* Validate file before upload
*
* @param file - File to validate
* @param maxSizeMB - Maximum file size in MB
* @param allowedTypes - Allowed MIME types
* @returns Validation result
*/
validateFile(file: File | Blob, maxSizeMB?: number, allowedTypes?: string[]): {
valid: boolean;
error?: string;
};
}