React File Upload Button
A modern, customizable React file upload component with drag-and-drop support, progress tracking, and file validation.
Installation
npm install react-file-upload-button Configuration
File Upload
📤
Drag & Drop
Intuitive drag-and-drop interface or click to browse files
🔒
File Restrictions
Control file types and sizes with custom validation messages
📊
Progress Bar
Visual feedback with customizable upload progress
Basic Usage
import UploadButton from 'react-file-upload-button';
function App() {
const handleFileUpload = (file) => {
console.log('File uploaded:', file);
};
const handleError = (error) => {
console.error('Upload error:', error);
};
return (
<UploadButton
onFileUpload={handleFileUpload}
onError={handleError}
/>
);
} Advanced Configuration
<UploadButton
maxSizeMB={10}
restrictFileSize={true}
allowedFileTypes={['.pdf', '.jpg', '.png']}
onFileUpload={handleFileUpload}
onError={handleError}
progressBarInterval={100}
showPreview={true}
showFileIcon={true}
uploadText="Drag & Drop or Click"
subText="Max size: 10MB"
/> Available Props
| Prop | Type | Default | Description |
|---|---|---|---|
| maxSizeMB | number | 10 | Maximum file size in megabytes |
| restrictFileSize | boolean | false | Enforce file size restriction |
| allowedFileTypes | string[] | undefined | Array of allowed file extensions |
| onFileUpload | function | required | Callback when file is uploaded |
| onError | function | required | Callback for error handling |
| progressBarInterval | number | 100 | Progress bar update interval (ms) |
| showPreview | boolean | false | Show file preview after upload |
| showFileIcon | boolean | true | Show file icon in upload area |
| uploadText | string | JSX | - | Custom upload text |
| subText | string | JSX | - | Custom subtitle text |
Key Features
✨
Drag and Drop
Intuitive drag-and-drop interface with click-to-browse fallback
📊
Progress Tracking
Visual progress bar with customizable update intervals
🔒
File Validation
Restrict file types and sizes with automatic validation
🎨
Customizable
Fully customizable text, icons, and styling options
👁️
File Preview
Optional preview of uploaded files with detailed information
⚡
Error Handling
Comprehensive error handling with custom callbacks
Built with ❤️ by Sridhar-C-25