We use cookies to ensure you get the best experience on our website. Read our privacy policy

Skip to main content

Directory

File Upload Component

The File Upload component provides a robust, user-friendly interface for uploading files. It supports drag-and-drop, multiple file selection, progress tracking, and comprehensive file validation.

  • Check Circle

    Drag & Drop: Intuitive file dropping interface

  • Check Circle

    Progress Tracking: Real-time upload progress visualization

  • Check Circle

    File Validation: Type and size restrictions

  • Check Circle

    Multiple Layouts: Table and card view options

Upload Files

Drag and Drop Files Here or Click to Upload

Accepted File Types: .jpg, .png, .pdf

Max File Size: 5MB

File Name File Size Actions
<FileUpload
id="basic-upload"
label="Upload Files"
accept={['.jpg', '.png', '.pdf']}
maxSize={5}
/>

Choose between two display styles for uploaded files, drag a file into the upload area’s below to see it in action. Your files will not be uploaded, this is a demo:

Table Layout

Drag and Drop Files Here or Click to Upload

Accepted File Types: .jpg, .png

Max File Size: 10MB

File Name File Size Actions
Card Layout

Drag and Drop Files Here or Click to Upload

Accepted File Types: .jpg, .png

Max File Size: 10MB

Disabled Upload

Drag and Drop Files Here or Click to Upload

Accepted File Types: .jpg, .png

Max File Size: 5MB

File Name File Size Actions
Error State

Drag and Drop Files Here or Click to Upload

Accepted File Types: .jpg, .png

Max File Size: 5MB

File Name File Size Actions
File Upload Component Extends <div> HTMLElement
Prop Type Default Description
accept string | string[] * Allowed file types (e.g., [".jpg", ".pdf"])
actionLabel string Select Files Text for the upload button
disabled boolean false Disable the upload functionality
label string undefined Label text above the upload area
labelProps HTMLAttributes<"label"> undefined Additional label element props
maxSize number 10 Maximum file size in MB
maxFiles number undefined Maximum number of files to upload
multiple boolean false Allow multiple file uploads
variant table | card table Layout style for uploaded files

The component provides several functions to manage the upload lifecycle.

File Upload Component Functions
Function Type Description
updateProgress ({ name: string, percent: number }) => void Update the progress of a file by its name (0 - 100)
set: uploadFileHandler ({ file: File }) => Promise<{ url?: string; error?: string }> Define a function to handle file uploads
set: removeFileHandler ({ fileName: string }) => void Define a function to handle file removals
set: validateFileHandler ({ file: File }) => boolean Define a function to handle custom file validations
get: fileList Map<string, { url?: string; error?: string }> Get a list of uploaded files
  • Check Circle

    File Type: Validates against accept prop

  • Check Circle

    File Size: Enforces maxSize limit

  • Check Circle

    Multiple Files: Respects multiple prop setting

  • Check Circle

    Max Files: Respects maxFiles limit

  • Check Circle

    Custom Validation: Supports additional validation through handlers

The component supports additional validation through handlers. You can set the validateFileHandler prop to a function that returns a boolean value indicating whether the file is valid.

This component doesn’t handle the file upload, it only provides a UI for the user to upload files. You need to handle the file upload in your own code defined in the uploadFileHandler function.

Limited Time Launch Sale

Start building accessible file upload experiences today with our AstroJS starter template.

GET 60% OFF!
North Star Themes Logo

Subscribe to our newsletter

Get the latest AstroJS tips and tricks right to your inbox

Email: [email protected]

© 2025 North Star Themes

Web Kit Provided By North Star Themes