Skip to content

File Upload

The File Upload element provides an intuitive way for users to upload files in your application. It supports both single and multiple file uploads with interactive drag-and-drop functionality, file validation, and extensive customization options to match your design system.

Features

  • Single or Multiple File Uploads: Easily configure for accepting one file or multiple files
  • Drag-and-Drop Support: Intuitive interface with animated visual feedback
  • File Validation: Configure size limits and file type restrictions
  • Visual Customization: Extensive styling options for all component elements
  • Upload Progress: Built-in visual progress indicator
  • Accessibility: Fully accessible with ARIA attributes and keyboard navigation
  • File Preview: Displays file information with size and upload progress
  • Base64 and Binary Formats: Option to expose file contents in Base64 or binary formats
  • Responsive Design: Adapts to container size and different screen dimensions

Getting Started

Using AI

The quickest way to set up the file upload is by using AI.

  1. Ask AI to add the file upload. Make sure to specify:
    • Specific styling requirements
    • Settings you would like applied:
AI Prompt
  1. The AI will then create your styled file upload:
AI visual
  1. Continue refining your file upload by asking AI for specific modifications:
    • "Make the file upload accept multiple image files"
    • "Add a custom label to the file upload"
    • "Change the border style to solid with a blue color"
    • "Show upload progress with a green progress bar"

Manual Setup

  1. Add the file upload to your page from the Add panel
  2. Configure basic settings:
    • Set upload type to single or multiple files
    • Configure file size limits (maximum and minimum)
    • Set allowed file types
    • Enable or disable drag and drop
  3. Customize appearance through the style panel
  4. Add workflows to handle file uploads and validation errors

Basic Configuration

Upload Types

The file upload supports two primary modes:

ModeDescriptionUse Case
Single FileAccepts only one file at a timeProfile photos, document submissions
Multiple FilesAccepts multiple filesPhoto galleries, batch document processing

File Validation

Control what files users can upload:

  1. File Size Limits:
    • Set maximum file size (default: 10MB)
    • Set minimum file size (default: 0MB)
    • For multiple uploads, configure maximum total size (default: 50MB)
Toggle Edition
  1. File Type Restrictions:
    • Choose from preset file types (Images, Videos, PDF, CSV, etc.)
Toggle Edition
  • Create custom extensions list (e.g., .docx, .pptx, .txt)
Toggle Edition

Drag and Drop

Enable intuitive file uploads:

  1. Set Allow drag & drop to On
  2. Users can drag files from their file explorer to the upload area
  3. Visual feedback appears as users drag over the component
Toggle Edition

Handling Uploads

When a user attempts to upload a file, the element:

  1. Provides visual feedback with drag animations
Toggle Edition
  1. Validates the file to ensure it meets the configured constraints
Toggle Edition
  1. Once uploaded, displays file information (name, size, type)
Toggle Edition
  1. Makes file data available through exposed variables
Toggle Edition
  1. Triggers workflow events allowing for further manual logic
Toggle Edition

Storing Uploads

On the backend

Ultimately, to correctly store uploaded files, you will likely need to save them in your backend.

As an example, imagine you had UI where the user's upload files and press a save button when done, like so

Toggle Edition

The steps to be taken would be the following:

  1. Have a workflow created on the save button to send the files and appropriately set any state variables (like loaders).

    Toggle Edition
  2. Inside the workflow, loop the files uploaded:

    Toggle Edition

    And for each file in the loop, send it to the backend for upload:

    Toggle Edition

TIP

In the example above, we looped the files because our file upload was set to allow multiple files. If your file upload is set to only allow single files, then you would not need to perform any looping.

On the frontend

You have the ability to store uploaded files into the WeWeb CDN, however, this is recommended to only be used for initial testing/MVPs.

To do so, you simply need the following:

  1. Have a workflow created on the file upload element with the On change trigger.

    Toggle Edition
  2. Inside the workflow, have an Upload file action linking to the file upload element:

    Toggle Edition
  3. The files will then be stored in the User Storage tab of the Auth menu:

    Toggle Edition

Advanced Options

Exposing File Content

For client-side processing, access file contents directly:

  1. Base64 Encoding:

    • Toggle Expose as Base64 to include base64-encoded file data
    • Useful for image previews or browser-based processing
  2. Binary Format:

    • Toggle Expose as Binary to include binary file data
    • Useful for advanced file manipulation like editing media or reading file metadata in detail.

Read-Only Mode

Present files without allowing changes:

  1. Set Read only to On
  2. Users can view uploaded files but cannot add or remove files
  3. Useful for review states or displaying previously uploaded content
Toggle Edition

Required Validation

Ensure users provide necessary files:

  1. Set Required to On
  2. File will be required as part of form submission
Toggle Edition

Example Use Cases

User Profile Photo Upload

Configure a single file upload for profile photos:

  1. Set upload type to Single file
  2. Set allowed file types to Image
  3. Set maximum file size to 5MB
  4. In the workflow, use the base64 data for preview
  5. Send the file to your server for storage

Document Management System

Create a multi-file document uploader:

  1. Set upload type to Multiple files
  2. Set allowed file types to PDF, Word, Excel or use custom extensions
  3. Set maximum total size to 50MB
  4. Add progress indicators and file management options
  5. Process uploads in batches

Build an image gallery uploader:

  1. Set upload type to Multiple files
  2. Set allowed file types to Image
  3. Enable base64 encoding for image previews
  4. Create a workflow to display uploaded images in a gallery
  5. Add file name display and size information

Best Practices

Do:

  • Provide clear instructions about file requirements
  • Set appropriate file size limits based on your application needs
  • Use the error event to provide helpful feedback

Don't:

  • Set unnecessarily restrictive file size limits
  • Use only generic error messages
  • Forget to handle uploaded files on your server

Forking

While the file upload element offers extensive built-in customization options, there may be cases where you need functionality beyond what's natively available. In these situations, you can fork the element and modify it to meet your specific requirements.

If you are unsure how to fork an element, you can learn more in the dedicated documentation.

Forking Example: Custom File Preview

One reason to fork the File Upload would be to add custom preview functionality:

I want to add image preview thumbnails to this forked file upload component

The AI will then add image preview capabilities:

Adding image previews through forking

Properties Reference

Settings

PropertyOptions/TypeDescription
Upload TypeSingle file, Multiple filesDetermines if one or multiple files can be uploaded
Allow drag & dropBooleanEnable/disable drag and drop functionality
Max file size (MB)NumberMaximum allowed file size
Min file size (MB)NumberMinimum allowed file size
RequiredBooleanMakes the file upload field required
Read onlyBooleanMakes the component read-only
Allowed file typesAny, Image, Video, Audio, PDF, CSV, Excel, Word, JSON, CustomPreset file type filters
Custom extensionsTextComma-separated list of allowed file extensions
Expose as Base64BooleanInclude base64-encoded file data
Expose as BinaryBooleanInclude binary file data

Styling

The File Upload component offers extensive styling options to match your application's design. These settings are organized into different sections in the properties panel.

Dropzone

The Dropzone section controls the appearance of the main drop area where users will drag files:

PropertyDescription
Border colorSet the color of the dropzone border
Border styleChoose between Solid, Dashed, Dotted, etc.
Border widthAdjust the thickness of the border (in pixels)
Border radiusControl the roundness of the dropzone corners
Background colorSet the background color of the dropzone
PaddingAdd space between the dropzone border and its contents
Min heightSet the minimum height of the dropzone

Dropzone styling

TIP

Using a dashed border with a light background color creates a visual cue that helps users identify the dropzone area.

Icon

The Icon section customizes the upload icon that appears in the dropzone:

PropertyDescription
Show upload iconToggle the visibility of the upload icon
Upload iconSelect which icon to display from the library
Icon colorSet the color of the icon
SizeAdjust the size of the icon (in pixels)
MarginControl the space around the icon
Icon positionChoose where the icon appears (Top, Left, Right, Bottom)

Icon styling

Label

The Label section controls the appearance of the primary text that appears in the dropzone:

PropertyDescription
LabelSet the text displayed in the dropzone (e.g., "Drop files here")
Font familyChoose the font for the label text
Font sizeAdjust the size of the label text (in pixels)
Font weightSet the boldness of the text
ColorChange the color of the label text
MarginControl the space around the label text

Label styling

TIP

Clear instructions in the label text help users understand what to do with the dropzone.

Info Messages

The Info Messages section controls the appearance of informational texts like file type restrictions:

PropertyDescription
Extensions messageCustomize the text that shows allowed file types
Extensions message font familyChoose the font for the extensions message
Extensions message font sizeSet the size of the extensions message text
Extensions message font weightControl the boldness of the extensions message
Extensions message colorSet the color of the extensions message
Extensions message marginControl the space around the extensions message
Max file messageCustomize the text that shows maximum file size
Max file message font familyChoose the font for the max file size message
Max file message font sizeSet the size of the max file size message
Max file message font weightControl the boldness of the max file size message
Max file message colorSet the color of the max file size message
Max file message marginControl the space around the max file size message

Info Messages styling

File List

The File List section controls how the list of uploaded files appears:

PropertyDescription
Background colorSet the background color of the file list container
Border colorSet the color of the border around the file list
Border radiusControl the roundness of the file list corners
PaddingAdd space inside the file list container
MarginControl the space around the file list container
ShadowAdd a shadow effect to the file list container
Progress bar colorSets color of progress bar shown when using Upload file workflow action

File Item Hover States

PropertyDescription
Hover border colorSet the border color when hovering over a file item
Hover background colorSet the background color when hovering over a file item
Hover shadowAdd a shadow effect when hovering over a file item

File List styling

File Name

PropertyDescription
Font familyChoose the font for file names
Font sizeSet the size of file name text
Font weightControl the boldness of file names
ColorSet the color of file name text

File Details

PropertyDescription
Show file detailsToggle the visibility of file details (size, type)
Font familyChoose the font for file details
Font sizeSet the size of file details text
Font weightControl the boldness of file details
ColorSet the color of file details text

File Name styling

Remove Buttons

The Remove Buttons section controls the appearance of the file removal buttons:

PropertyDescription
SizeSet the size of action buttons
Background colorSet the background color of action buttons
Hover background colorSet the background color when hovering over buttons
Icon colorSet the color of icons within the buttons
Border colorSet the color of the border around buttons
Hover border colorSet the border color when hovering over buttons
Remove button hover colorSet the hover color specifically for the remove button
Border radiusControl the roundness of button corners
MarginControl the space around buttons

Remove Buttons styling

Drag & Drop Animation

The Drag & Drop Animation section controls the visual feedback when files are dragged over the dropzone:

PropertyDescription
Enable circle animationToggle the circular animation when dragging files
Circle sizeSet the size of the animation circle
Circle colorSet the color of the animation circle
Circle opacityControl the transparency of the animation circle
Animation speedAdjust how fast the animation plays

TIP

A subtle animation provides helpful visual feedback to users when they're dragging files over the dropzone.

Event Triggers

EventDescriptionPayload
On changeTriggered when files are added or removed{ value: fileArray }
On init value changeTriggered when initial value changes{ value: fileArray }
On errorTriggered when file validation fails{ code: errorCode, data: errorData }

Example Event Payloads

On change

javascript
{
  value: [
    {
      name: "document.pdf",
      size: 1258000,
      type: "application/pdf",
      extension: "pdf",
      id: "file-1647889433265-x8f2j9s"
    }
  ]
}

Use this event to:

  • Save uploaded files to a database
  • Process files for further use
  • Update UI based on uploaded content

On init value change

javascript
{
  value: [
    {
      name: "document.pdf",
      size: 1258000,
      type: "application/pdf",
      extension: "pdf",
      id: "file-1647889433265-x8f2j9s"
    }
  ]
}

On error

javascript
{
  code: "MAX_SIZE_EXCEEDED",
  data: {
    message: "File size (15.5 MB) exceeds the maximum allowed size (10 MB)",
    fileName: "large-file.zip",
    fileSize: 16252880,
    fileType: "application/zip",
    constraint: "MAX_SIZE"
  }
}

Use this event to:

  • Show custom error messages
  • Guide users on how to resolve validation issues
  • Log upload attempts

Component Actions

ActionDescriptionParameters
Clear FilesClears all uploaded filesNone

Exposed Variables

VariableTypeDescription
valueArrayList of all files uploaded
statusArrayList of the upload status of all files (will only populate if the files are being uploaded to the frontend via the Upload file workflow action