Configuration object
A JSX element representing the file upload component
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',
},
Creates a file upload component for handling file uploads with validation and limits.