Configuration object
Name of the component
Title text or React node for the upload section
Helper text or React node to display
Text or React node for the error message to display
Text to display during file upload. Default is 'loading'
Maximum number of files allowed. Default is 1
Minimum number of files required. Default is 1
Async function to validate uploaded files. Takes a file as input and returns a Promise containing validation results
Object containing an array of allowed file types (MIME types like 'application/pdf' or file extensions like '.pdf', '.jpg') and a message to display if the file type is not allowed
Object containing a size in bytes and a message to display if the file size is too large
validFiles and droppedFiles. Every array element is the same object type.export interface DroppedMwFile {
name: string;
type: string;
isValid?: boolean;
message?: string;
processedFile?: any;
webUrl?: string;
fileId: string;
arrayBuffer?: ArrayBuffer;
}
maxFileSize prop.maxFileSize: {
size: 5 * 1024 * 1024, // 5MB
message: 'File size must be less than 5MB',
}
allowedTypes prop. You can specify MIME types (e.g. 'application/pdf') or file extensions (e.g., '.pdf', '.jpg').allowedTypes: {
types: ['application/pdf', '.xlsx', '.docx'],
message: 'File type must be an image, PDF, Excel, or Word document',
}
validate: (file: DroppedMwFile) => Promise<{
isValid: boolean;
message: string;
processedFile?: any;
}>;;
validate function is optional. If not provided, all files will be considered valid.validate function is called when the user drops a file into the upload area or selects a file from the file system.Basic usage with required props
fileUpload({
name: 'upload-file',
fileUploadTitle: 'Upload Files',
});
Usage with required and optional props
fileUpload({
name: 'upload-file',
fileUploadTitle: 'Upload Files',
text: 'Please select file to upload.',
error: 'You can upload up to 3 files only.',
maxFileLimit: 3,
minFileLimit: 1,
Usage with file validate function
fileUpload({
name: 'upload-file',
fileUploadTitle: 'Upload Files',
validate: async (file) => {
const isValid = false // Apply your validation logic here
const message = isValid ? '' : 'File is not valid'
return {
isValid,
message,
processedFile: file
};
}
});
Usage with file size and type validation (MIME types and extensions)
fileUpload({
name: 'upload-file',
fileUploadTitle: 'Upload Files',
maxFileSize: {
size: 5 * 1024 * 1024, // 5MB
message: 'File size must be less than 5MB',
},
allowedTypes: {
types: ['application/pdf', '.xlsx', '.docx'],
message: 'File type must be a PDF, Excel, or Word document',
},
File upload component for handling file uploads with validation and limits.