Dropzone
A file upload component with drag-and-drop support, file validation, and upload progress tracking.Props
The return value from the
useConvexUpload hookAdditional CSS classes to apply to the component
Hook: useConvexUpload
The component requires theuseConvexUpload hook for managing file upload state.
Hook Options
Allowed MIME types for file uploads. Supports wildcards (e.g.,
"image/*", "text/html"). Empty array allows all types.Maximum upload size per file in bytes (e.g., 1000 bytes = 1 KB)
Maximum number of files allowed per upload
Hook Return Values
Array of files selected for upload
Function to update the files array
Upload in progress state
Array of upload errors
Array of successfully uploaded file names
True if all files uploaded successfully with no errors
Function to trigger file upload
Maximum file size setting
Maximum files setting
Allowed MIME types setting
Props for the dropzone root element (from react-dropzone)
Props for the file input element (from react-dropzone)
True when files are being dragged over the dropzone
Function to programmatically open file picker
Types
Example
Direct Hook Usage
Upload Flow
- Files are selected via drag-and-drop or file picker
- Files are validated against
allowedMimeTypes,maxFileSize, andmaxFiles - Valid files are added to the
filesarray with preview URLs (for images) - Invalid files are added with their validation errors
- User clicks upload button (or calls
onUpload()) - For each file:
- Generate upload URL via
generateUploadUrlmutation - Upload file to Convex storage via fetch POST
- Save file metadata to database via
saveFilemutation
- Generate upload URL via
- Track successes and errors per file
- Support partial uploads - can retry failed files
Features
- Drag-and-drop support
- File type validation with MIME types
- File size validation
- Maximum file count enforcement
- Image preview generation
- Upload progress tracking
- Per-file error handling
- Partial upload support (retry failed files)
- Visual feedback for drag state, loading, success, and errors
- File type icons for different MIME types