Skip to content
Files SDK
Esc
navigateopen⌘Jpreview
On this page

Dropzone

A drag-and-drop (or click) upload area wired to useFiles, with composable empty and uploaded states.

A compound dropzone that uploads through a useFiles instance. Drag files in or click to open the picker; bytes stream straight to your gateway.

"use client";

import { demoFiles } from "@/lib/demo-files";
import {
  Dropzone,
  DropzoneContent,
  DropzoneEmptyState,
} from "@/registry/files-sdk/dropzone/dropzone";

const Example = () => {
  const files = demoFiles;

  return (
    <Dropzone accept="image/*" files={files} prefix="demo/">
      <DropzoneEmptyState />
      <DropzoneContent />
    </Dropzone>
  );
};

export default Example;

Installation

npx shadcn@latest add https://files-sdk.dev/r/dropzone.json

Usage

import { useFiles } from "files-sdk/react";

import {
  Dropzone,
  DropzoneContent,
  DropzoneEmptyState,
} from "@/components/files-sdk/dropzone";

export function Uploader() {
  const files = useFiles({ endpoint: "/api/files" });

  return (
    <Dropzone accept="image/*" files={files} prefix="docs/" maxFiles={5}>
      <DropzoneEmptyState />
      <DropzoneContent />
    </Dropzone>
  );
}

DropzoneEmptyState renders the prompt until something uploads; DropzoneContent renders the result afterwards. Pass your own children to either to override the default look.

Props

<Dropzone>

PropType
filesUseFilesResult

A `useFiles()` instance — the dropzone uploads through it.

TypeUseFilesResult
prefix?string

Key prefix (folder) for explicit keys, e.g. `"docs/"`. Empty = server mints the key.

Typestring
accept?string

`accept` attribute for the file input, e.g. `"image/*"`.

Typestring
maxFiles?number

Max files per drop. Default 1.

Typenumber
maxSize?number

Max bytes per file; larger files are skipped.

Typenumber
onUploaded?(entry: UploadedEntry) => void

Called after each successful upload.

Type(entry: UploadedEntry) => void
className?string
Typestring
children?ReactNode
TypeReactNode

<DropzoneEmptyState> and <DropzoneContent> each accept className and children to override the default look.

Was this page helpful?