Frontend School

Batch Asset Uploader

Machine Coding
hard

Batch Asset Uploader

Hard
React
TypeScript
File Upload
Drag and Drop
Progress Bar
Concurrency

Overview

Clevertap's marketing platform empowers users to create engaging campaigns. A critical part of this process is uploading various assets like images and videos. We need a robust and user-friendly "Batch Asset Uploader" component that allows users to efficiently upload multiple files, monitor their progress, and handle potential issues. This problem challenges your ability to manage concurrent operations, handle UI updates, and provide a smooth user experience.

What you need to do / Task

Your goal is to build a React component called BatchAssetUploader that provides the following functionalities:

  1. File Selection:
    • Allow users to select multiple files using a standard file input button.
    • Implement a drag-and-drop interface for selecting files.
  2. File List Display:
    • As files are selected (either via button or drag-and-drop), display them in a list.
    • For each file, show its name, size, current status (e.g., "Pending", "Uploading", "Completed", "Failed"), and a progress bar during upload.
  3. Upload Simulation:
    • Simulate an asynchronous file upload process. You do not need a real backend.
    • Each file upload should take a random duration between 2 to 5 seconds.
    • Simulate upload progress updates (e.g., update progress bar every 200ms).
    • Randomly simulate failures for approximately 20% of uploads.
  4. Upload Cancellation:
    • Provide a "Cancel" button next to each actively uploading file.
    • Clicking "Cancel" should stop the ongoing simulated upload for that specific file and update its status to "Cancelled".
  5. Client-side Validation:
    • Before starting an upload, validate each file:
      • Max Size: Files must not exceed 5MB.
      • Allowed Types: Only image files (JPEG, PNG, GIF) and video files (MP4, WebM) are allowed.
    • Display clear error messages for invalid files (e.g., "File too large", "Unsupported file type").
  6. Overall Status:
    • Provide a summary of the upload process (e.g., "X files uploaded successfully, Y failed, Z pending").

UI/UX expectations

  • Drag-and-Drop Zone: A clearly demarcated area (e.g., a dashed border) that visually indicates when files are being dragged over it.
  • File List: A scrollable list displaying each selected file. Each item should include:
    • File icon (optional, but good if included).
    • File name and size.
    • Progress bar for active uploads.
    • Status text (e.g., "Uploading (50%)", "Completed", "Failed", "Cancelled", "Pending").
    • A "Cancel" button for files in "Pending" or "Uploading" state.
    • Clear error messages for failed uploads or validation issues.
  • Feedback: Provide immediate feedback on file selection, drag-over states, and upload progress/status.

Acceptance criteria

  • Users can select multiple files via a button.
  • Users can drag and drop multiple files into the designated area.
  • Files exceeding 5MB are rejected with an error message.
  • Files of unsupported types are rejected with an error message.
  • Each valid file displays its name, size, and current status in a list.
  • Uploading files show an individual progress bar that updates dynamically.
  • Clicking "Cancel" on an uploading file stops its progress and marks it as "Cancelled".
  • Upload failures (simulated) are clearly indicated with an error message.
  • A summary displays the count of successfully uploaded, failed, and pending/active files.
  • The UI remains responsive during concurrent uploads.

Constraints

Constraints & assumptions

  • Technology Stack: React with TypeScript.
  • No Backend: All file upload operations must be simulated on the client-side. Do not attempt to send files to a server.
  • Concurrency: The component should be able to handle multiple simultaneous uploads (up to the maximum allowed by the browser, typically 6-8 concurrent HTTP requests, but for simulation purposes, you can assume all valid files start uploading concurrently).
  • File Limit: Max 5 files can be processed at once. If more are selected, only the first 5 should be accepted.
  • File Size: Maximum file size for validation is 5MB (5 * 1024 * 1024 bytes).
  • Allowed Types: image/jpeg, image/png, image/gif, video/mp4, video/webm.
  • Simulated Upload Details:
    • Progress updates should occur frequently enough to show smooth animation (e.g., every 200ms).
    • Simulate a random failure for approximately 20% of uploads.
    • Use AbortController for cancellation.

Out of scope

  • Server-side file processing, storage, or actual API integration.
  • Advanced UI features like image/video previews (thumbnails).
  • Deep browser compatibility testing (focus on modern browser features).
  • Persistent storage of upload status across page refreshes.

What interviewers evaluate

  • Component Design & Architecture: Modularity, separation of concerns, and effective use of React hooks.
  • State Management: How well the component manages the state of multiple concurrent file uploads, including progress, status, and errors.
  • Error Handling & User Feedback: Robust client-side validation, clear error messages, and graceful handling of simulated upload failures and cancellations.
  • Concurrency Management: Proper use of AbortController for cancellation and handling multiple async operations.
  • Code Quality: Readability, maintainability, type safety (TypeScript usage), and adherence to best practices.

Loading editor...