Home / Forms and Input / File Upload Dropzone

File Upload Dropzone in JavaScript, Free with Live Demo

Free file upload dropzone in plain JavaScript. Drag files in or pick them, see image previews, reject wrong types and big files, watch progress bars and remove files.

Open live demoDownload HTML fileView code on GitHub
File Upload Dropzone JavaScript project: a drag and drop uploader with previews, size limits and progress bars

Runs on: File API and drag and drop events. Works in all modern browsers.

What is the File Upload Dropzone?

A drag and drop upload box. Drop images or PDFs in, click to choose, or paste an image from the clipboard, and see each file listed with a preview.

Files that are too big or the wrong type are refused with a clear reason. Press Upload to see progress bars for each file.

Good for

  • Contact forms with attachments
  • Job applications with a CV
  • Profile and product photo uploads
  • Support tickets with screenshots

What this project does

How it works

  1. Accept files three waysClick opens the file picker, dropping uses the drop event, and pasting reads clipboard files. All three go to one add function.
  2. Check before uploadEach file is checked for type and size right away, so people see the problem before they wait for anything.
  3. Preview without uploadingURL.createObjectURL shows a local image preview instantly. The URL is revoked when the file is removed.

The key JavaScript

This is the heart of the project. The full file has the rest, including the screen layout and error handling.

zone.addEventListener("drop", (e) => {
  e.preventDefault();
  for (const file of e.dataTransfer.files) {
    if (!["image/png", "image/jpeg", "application/pdf"].includes(file.type)) continue;
    if (file.size > 5 * 1024 * 1024) continue;           // 5 MB limit
    const img = new Image();
    img.src = URL.createObjectURL(file);                  // instant preview
    list.append(img);
  }
});
// real upload: fetch("/upload", { method: "POST", body: formData })

How to use it

  1. Click Download HTML file above.
  2. Open the file in a code editor, like VS Code.
  3. Run it from a local server with npx serve . so the camera, microphone and AI features are allowed.
  4. Change the text and colors, then upload it to GitHub Pages, Netlify or your own site. It is one file with no build step.

Questions people ask

Does this upload to a server?

The demo simulates the upload. To send files for real, add them to a FormData object and post it with fetch.

Can I show real upload progress?

Yes. fetch does not report upload progress yet, so use XMLHttpRequest and its upload.onprogress event.

Is the accept attribute enough?

No. It only filters the picker. Always check type and size in JavaScript and again on the server.

More Forms and Input projects