EdgeStore

Multi-file

A component for uploading multiple files with a progress list, retry and a running total.

Click to upload or drag and drop

up to 1 MB each · 10 max

Each file shows its type, size and progress. Failed uploads show the error with a retry button, and running uploads can be canceled.

Installation

Use the shadcn CLI to add the component to your project.

npx shadcn@latest add https://edgestore.dev/r/file-uploader.json

Usage

Install or copy the component from Installation before using this example.

'use client';

import { FileUploader } from '@/components/upload/multi-file';
import {
  UploaderProvider,
  type UploadFn,
} from '@/components/upload/uploader-provider';
import { useEdgeStore } from '@/lib/edgestore';
import * as React from 'react';

export function MultiFileDropzoneUsage() {
  const { edgestore } = useEdgeStore();

  const uploadFn: UploadFn = React.useCallback(
    async ({ file, onProgressChange, signal }) => {
      const res = await edgestore.publicFiles.upload({
        file,
        signal,
        onProgressChange,
      });
      // you can run some server action or api here
      // to add the necessary data to your database
      console.log(res);
      return res;
    },
    [edgestore],
  );

  return (
    <UploaderProvider uploadFn={uploadFn} autoUpload>
      <FileUploader
        maxFiles={5}
        maxSize={1024 * 1024 * 1} // 1 MB
        accept={{
          'application/pdf': ['.pdf'],
          'text/plain': ['.txt'],
        }}
        typesLabel="PDF or TXT"
      />
    </UploaderProvider>
  );
}

Props

PropTypeDefaultDescription
maxFilesnumberMaximum number of files in total.
maxSizenumberMaximum file size in bytes.
acceptAcceptall typesAccepted file types, in react-dropzone's format.
typesLabelstringHuman-readable list of accepted types, shown in the hint and in error messages.
disabledbooleanfalseDisables the component.
dropzoneClassNamestringAdditional className for the dropzone.
fileListClassNamestringAdditional className for the file list.

Building your own layout

multi-file.tsx also exports the pieces it is made of, so you can arrange them differently:

  • FileList lists the files of the nearest UploaderProvider.
  • FileListItem renders one file with its status and actions.
  • FileBadge renders the colored file-type tile.

On this page