Frontend School

Secure Multi-File Document Uploader

Machine Coding
medium

Secure Multi-File Document Uploader

Medium
File Upload
UI
React
Frontend
State Management
Asynchronous Operations

Overview

In a modern document management system, users frequently need to upload multiple sensitive files simultaneously. A robust and user-friendly file upload component is crucial for ensuring a smooth experience, providing clear feedback on upload progress, and handling potential issues like invalid files or network failures.

What you need to do / Task

Your task is to build a React component that enables users to select and upload multiple files. You will need to simulate the asynchronous nature of file uploads and provide comprehensive feedback on their status.

  1. File Selection: Implement a mechanism for users to select one or more files from their local system.
  2. File List Display: Display a list of all selected files, showing their names, sizes, and initial 'Ready' status.
  3. File Removal: Allow users to remove individual files from the list before initiating the upload process.
  4. Mock Upload Functionality: Create a mockUploadFile asynchronous function that simulates network latency (1-3 seconds) and introduces a ~20% chance of failure for any given file. This function should also report progress.
  5. Upload Process & Feedback: Implement an 'Upload All' button that initiates the mock upload for all 'Ready' files. During the upload, each file should display a progress indicator and its current status (e.g., 'Uploading...', 'Uploaded', 'Failed').
  6. Overall Status: Provide an overall status message to the user indicating whether all uploads completed successfully, some failed, or if the process is ongoing.

UI/UX expectations

  • A clear button to trigger file selection.
  • A list area displaying selected files. Each list item should show:
    • File name and size.
    • Current status (Ready, Uploading, Uploaded, Failed).
    • A progress bar/indicator for files actively uploading.
    • A 'Remove' button (e.g., an 'X') for files not yet uploaded or that failed.
  • An 'Upload All' button to start the process for all selected files.
  • Clear, concise messages for overall upload status (e.g., "Uploading files...", "All files uploaded", "Some uploads failed").
  • The UI should be functional and easy to understand, even with basic styling.

Acceptance criteria

  • Users can select multiple files using a standard file input.
  • Selected files are displayed in a list with their name and size (in MB).
  • Users can remove individual files from the list before upload.
  • The 'Upload All' button becomes active only when files are selected.
  • Clicking 'Upload All' initiates a mock asynchronous upload for each 'Ready' file.
  • Each file displays a progress bar during its mock upload.
  • Each file's status updates correctly to 'Uploaded' or 'Failed' upon completion of its mock upload.
  • An overall status message is displayed, reflecting the aggregate outcome of all uploads.
  • File selection adheres to specified type and size constraints, providing feedback for invalid files.

Constraints

Constraints & assumptions

  • Max Files: A maximum of 5 files can be selected for upload at any given time.
  • Max File Size: Individual files must not exceed 5MB.
  • Allowed File Types: Only PDF, DOC/DOCX, TXT, JPG, PNG files are allowed.
  • Mock Upload: The mockUploadFile function should simulate network latency (1-3 seconds) and a ~20% chance of failure for each file.
  • Frontend Only: No actual backend integration is required. All file handling and 'upload' logic should be simulated on the client-side.
  • Environment: Use React for building the UI component.

Out of scope

  • Drag-and-drop functionality for file selection.
  • Advanced accessibility features beyond basic semantic HTML elements.
  • Complex styling or animations (basic functional styling is sufficient).
  • Persistent storage of uploaded files (e.g., local storage, IndexedDB).

What interviewers evaluate

  • Component Design & State Management: How effectively the file upload component is structured, and how its state (selected files, upload status, progress) is managed using React hooks.
  • Asynchronous Logic & Error Handling: Proficiency in simulating asynchronous operations (mockUploadFile) and gracefully handling their lifecycle, including success, failure, and progress updates.
  • User Experience & Feedback: The clarity and responsiveness of the UI feedback provided to the user throughout the file selection and upload process.
  • Code Quality & Readability: Adherence to best practices for clean, maintainable, and well-organized React code, including appropriate type definitions (TypeScript).

Loading editor...