Skip to content

File Upload

Download .md

A file upload takes files by drag and drop or from the file picker, then lists each file with its size, its progress and any error, such as a master audio file.

  • Use it when a form needs a file: a master, a cover letter, a contract.
  • Write the allowed types and the size limit in the hint: “WAV atau FLAC, maks. 200 MB.”
  • The client only narrows the picker with accept. The backend checks what is inside the file, and its message shows under that file.
  • On phones there is nothing to drag: the area works as a button that opens the picker.
React

WAV atau FLAC, maks. 200 MB.

  • demo-lama.mp34,1 MB
Vue

WAV atau FLAC, maks. 200 MB.

  • demo-lama.mp34,1 MB
1234
  1. 1Drop zone, also a button
  2. 2Upload icon
  3. 3File row
  4. 4Upload progress
Part Style
Drop area rounded-lg, a dashed input border, bg-muted/30, 24px padding, centered. On hover and while dragging, border-primary and bg-primary-soft.
Text “Tarik file ke sini atau pilih file”, then the hint in text-xs muted-foreground.
File row One row per file on card with a border: name, size, a Progress bar while it uploads, and a remove button.
Error The backend’s message under the file in destructive; the row border turns destructive.
React Vue Flutter Type Default Use
accept accept file_picker allowedExtensions text any Narrows the picker, such as .wav,.flac.
multiple multiple allowMultiple boolean false Lets people add several files.
files, onFilesChange v-model:files your list { file, progress?, error? }[] [] The files, with progress (0–100) and the backend’s error.
onRemove @remove your handler function none Runs after a file is removed, for example to cancel its upload.
hint, error hint, error Text text none The limits, and a backend message about the whole upload.
label, buttonLabel label, button-label Text text English The area’s text: label from sm up, buttonLabel on phones, such as “Pilih file”.
removeLabel, uploadingLabel same Semantics function English Names the buttons and bars, such as “Hapus master.wav”.
locale locale NumberFormat locale text en-GB How file sizes read, such as "id-ID" for 4,1 MB.

Flutter has no upload widget; the snippet draws the area from the theme, and products open the picker with the file_picker package.

import { useEffect, useState } from "react"
import { FileUpload, type FileUploadItem } from "@/components/ui/file-upload"
/** A file the backend already turned down, so the demo shows the error state. */
const rejected = new File(["demo"], "demo-lama.mp3", { type: "audio/mpeg" })
Object.defineProperty(rejected, "size", { value: 4_300_000 })
export default function FileUploadDemo() {
const [files, setFiles] = useState<FileUploadItem[]>([{ file: rejected, error: "Format file-nya belum pas." }])
// Pretend to upload: new files fill their progress bar, then settle.
useEffect(() => {
if (!files.some((f) => f.progress !== undefined)) return
const timer = setTimeout(
() =>
setFiles((list) =>
list.map((f) => (f.progress === undefined ? f : f.progress >= 100 ? { file: f.file } : { ...f, progress: f.progress + 25 }))
),
400
)
return () => clearTimeout(timer)
}, [files])
return (
<FileUpload
className="max-w-md"
accept=".wav,.flac"
multiple
label="Tarik file ke sini atau pilih file"
buttonLabel="Pilih file"
locale="id-ID"
hint="WAV atau FLAC, maks. 200 MB."
removeLabel={(name) => `Hapus ${name}`}
uploadingLabel={(name) => `Mengunggah ${name}`}
files={files}
onFilesChange={(next) => setFiles(next.map((f) => (files.includes(f) ? f : { file: f.file, progress: 0 })))}
/>
)
}
Terminal window
npx shadcn@latest add https://design.sosialoka.tech/r/react/file-upload.json
  • The drop area is a button: Enter and Space open the file picker.
  • The hint and the backend’s error about the whole upload are linked to the area with aria-describedby.
  • Each remove button is named after its file, such as “Hapus master.wav”, and a file’s error is linked to it.
  • Each progress bar is named, such as “Mengunggah master.wav”.