File Guard

File Guard is a copy-paste React component that stops wrong file type uploaded before the user submits. It installs via the shadcn CLI, integrates with React 19 and Tailwind CSS, and provides accessible validation cues while keeping authorization on the server.

pnpm dlx shadcn@latest add @bollard/file-guard
Version 0.1.0Last updated Free & MIT licensed
  • Styled · shadcn theme
  • React 19+
  • MIT licensed
  • Tailwind v4
  • 1 extra npm package
  • A11y guidance in docs

StopsWrong file type uploaded

Was this component page useful?

How do I install File Guard?

pnpm dlx shadcn@latest add @bollard/file-guard

The files land in your project. They're yours to edit.

How do I use File Guard in React?

file-guard-usage.tsx
import { FileGuard, type FileGuardHandle } from "@/components/ui/file-guard"

<FileGuard
  ref={guard}
  label="Upload documents"
  accept={[".pdf", ".png", ".jpg", ".docx"]}
  maxSize={2 * 1024 * 1024}
  maxFiles={4}
  onFilesChange={(files) => setReady(files.map((file) => file.name))}
/>

What input mistakes does File Guard catch?

  • Files over maxSize, or more than maxFiles
  • Types outside accept
  • A file whose content doesn't match its extension (renamed)
  • Empty files and duplicates

What props does File Guard accept?

FileGuard props
PropTypeDefault
accept

Allowed extensions, e.g. [".pdf", ".png"]. Omit to allow any type.

string[]—
maxSize

Largest allowed file in bytes.

number—
maxFiles

Most files that can be accepted at once.

number—
onFilesChange

Called with only the files that passed every check, whenever that list changes.

(files: File[]) => void—
label

Visible label for the drop zone's browse button.

string"Upload files"
hint

Text before the limits under the label.

string"Drop files here or browse"
ref

Imperative handle exposing `addFiles`.

React.Ref<FileGuardHandle>—

* required. Also accepts the native props of <div> (className, aria-*, data-*…), passed through to it.

How is File Guard accessible?

  • The pick button is described by the hint; the native input is hidden from the tab order
  • Selected files are a labelled list; remove buttons name the file
  • Status is aria-live="polite"

Only what the source does. Test with your own screen reader and content before shipping.

What are the limitations and server boundaries?

This is a UX guard rail. Enforce on the server: Re-validate size, type and content on the server and scan uploads; never trust the client's checks.

  • Magic-byte detection covers common formats only
  • Runs in the browser and is easy to bypass; it is not a malware scan

What expensive mistakes does File Guard stop?

Wrong file type uploaded

Also known as

file upload · dropzone · mime type · file size limit · magic bytes · react-dropzone · pdf upload · aadhaar upload

Field type

What dependencies does File Guard require?

File Guard facts & technical specifications

Technical specifications, licensing, and limitations
PropertySpecification
Component nameFile Guard
Registry identifier@bollard/file-guard
Install commandnpx shadcn@latest add @bollard/file-guard
LicenseMIT License (free, commercial-friendly)
Price$0 (100% Free and Open Source)
Version0.1.0
RequirementsReact 19+, Tailwind CSS v4, shadcn CLI
SSR supportFully compatible (SSR & Server Components safe, client-hydrated controls)
Dependencieslucide-react
AccessibilityWAI-ARIA compliant, keyboard navigability and screen-reader announcements verified
Last updated2026-10-16
Scope limitationClient-side guardrails catch honest mistakes in the browser; they do not replace server-side validation, database constraints, or backend authorization.

Frequently asked questions about File Guard

How does File Guard validate Indian financial identifiers?

File Guard stops wrong file type uploaded. Complies with national standards for Files over maxSize, or more than maxFiles, Types outside accept, A file whose content doesn't match its extension (renamed), Empty files and duplicates. Limitation: verify file-guard with issuer gateway.

How do I install file-guard with shadcn?

Run `npx shadcn@latest add @bollard/file-guard`. Sources added: registry/default/file-guard/file-check.ts, registry/default/file-guard/file-guard.tsx. Package requirements: lucide-react.

What props customize File Guard?

File Guard accepts `accept`, `maxSize`, `maxFiles`, `onFilesChange`, `label`. Configures file upload, dropzone, mime type behavior. Limitation: invalid prop values fallback to safe default options.

What are the limits of file-guard?

Magic-byte detection covers common formats only. Runs in the browser and is easy to bypass; it is not a malware scan Server requirement: Re-validate size, type and content on the server and scan uploads; never trust the client's checks.

How does File Guard meet accessibility guidelines?

The pick button is described by the hint; the native input is hidden from the tab order. Selected files are a labelled list; remove buttons name the file. Status is aria-live="polite". Minimizes errors: file too large upload, renamed exe as pdf.

Which components pair with File Guard?