How file uploads work in HTML forms

A file input sends only the file name unless the form is set up correctly. Learn enctype, accept, multiple, size checks and uploading with FormData.

You added <input type="file"> to a form, picked a document, pressed submit, and the server received a file name with no file. This is the most common file upload mistake, and it comes down to one missing attribute.

This guide covers how file uploads work in HTML, how to restrict what people can choose, how to send files with JavaScript, and how uploads behave when the form posts to FormDB.

Why your form sends the file name and not the file

By default, a form encodes its data as application/x-www-form-urlencoded. This format is plain text: field names and values joined with = and &. It has no way to carry the contents of a file, so the browser sends the file's name as the value and nothing more.

To send real files, the form needs a different encoding, set with the enctype attribute:

<form action="https://api.formdb.io/f/your-form-id" method="POST" enctype="multipart/form-data">
  <label for="name">Name</label>
  <input id="name" type="text" name="name" required>

  <label for="resume">Resume</label>
  <input id="resume" type="file" name="resume" required>

  <button type="submit">Apply</button>
</form>

multipart/form-data splits the request body into parts, one per field, separated by a boundary string the browser generates. Text fields become small text parts. File fields become parts that contain the file's bytes along with its name and type.

Two requirements go with it:

  • The method must be POST. A GET form puts its data in the URL, which cannot hold a file.
  • The file input needs a name, like every other field.

Limit file types with the accept attribute

The accept attribute tells the browser which kinds of file to offer in the file picker:

<input type="file" name="resume" accept=".pdf,.doc,.docx">
<input type="file" name="photo" accept="image/*">

You can list file extensions (.pdf), exact media types (application/pdf), or wildcards such as image/*.

accept is a convenience, not a security control. It filters what the picker shows, but visitors can usually switch the picker to "all files", and anyone posting to your endpoint without a browser is not affected by it at all. The server has to check the type again.

Allow several files with the multiple attribute

Add multiple to let a visitor choose more than one file in the same input:

<input type="file" name="attachments" multiple>

The browser then sends one part per file, all under the same field name. On the receiving side, a field name that appears several times is treated as a list.

Check file size before uploading

HTML has no attribute for a maximum file size. Without a check, a visitor can wait through a long upload only to have the server reject it at the end.

JavaScript can read the size of each chosen file before anything is sent, through the input's files property:

const input = document.querySelector("#resume");
const maxBytes = 5 * 1024 * 1024; // 5 MB

input.addEventListener("change", () => {
  const tooBig = Array.from(input.files).some((file) => file.size > maxBytes);
  input.setCustomValidity(tooBig ? "Each file must be 5 MB or smaller." : "");
  input.reportValidity();
});

setCustomValidity marks the field as invalid with your message, so the browser blocks the submit in the same way it does for an empty required field.

As with accept, this helps honest visitors and stops nobody else. The limit that counts is the one enforced on the server.

Upload files with FormData and fetch

To upload without leaving the page, use FormData, a browser object that packages form fields, including files, into a multipart/form-data body.

<form id="apply" action="https://api.formdb.io/f/your-form-id" method="POST" enctype="multipart/form-data">
  <label for="email">Email</label>
  <input id="email" type="email" name="email" required>

  <label for="resume">Resume (PDF)</label>
  <input id="resume" type="file" name="resume" accept=".pdf" required>

  <button type="submit">Apply</button>
  <p id="apply-status" role="status"></p>
</form>

<script>
  const form = document.querySelector("#apply");
  const applyStatus = document.querySelector("#apply-status");

  form.addEventListener("submit", async (event) => {
    event.preventDefault();
    applyStatus.textContent = "Uploading...";

    try {
      const response = await fetch(form.action, {
        method: "POST",
        headers: { Accept: "application/json" },
        body: new FormData(form),
      });
      const body = await response.json();

      if (response.ok) {
        form.reset();
        applyStatus.textContent = "Thanks, your application was received.";
      } else {
        applyStatus.textContent = body.error.message;
      }
    } catch (err) {
      applyStatus.textContent = "Upload failed. Check your connection and try again.";
    }
  });
</script>

Two rules prevent most problems here:

  • Do not set the Content-Type header yourself. When the body is a FormData object, the browser sets multipart/form-data together with the boundary string. If you set the header by hand, the boundary is missing and the server cannot read the body.
  • Do not use JSON for files. A JSON body cannot carry a file. If your code sends JSON.stringify(...), switch to FormData for forms with uploads.

How file uploads work on FormDB

FormDB accepts files on the same endpoint as every other submission, as long as the request is multipart/form-data. The file input can have any name, and several files per field are allowed. A field named attachments[] is stored as attachments.

Plans and storage

File uploads work on every plan, including Free. Each plan includes a total amount of file storage for the workspace: 100 MB on Free, and from 2 GB on paid plans, as shown on the pricing page. When a submission's files do not fit in the remaining storage, it is rejected with status 413 and the error code storage_full, and it is not stored.

Storage is freed when submissions are permanently deleted or the form is deleted.

Size limits

One submission, counting all fields and files together, can be up to 50 MB. A larger request is rejected with status 413. For bigger files, FormDB's helper script can upload each file straight to storage before the form is sent. See file uploads.

Each plan also has a limit per file: 10 MB on Free, 25 MB on Starter, 100 MB on Growth and 250 MB on Business. Beyond that, FormDB does not set a fixed file count or a fixed list of allowed types. You set those, and a lower size limit if you want one, per field using validation rules.

Validation rules for file fields

Add a File upload field in the form builder with the same name as your input, then attach rules to it:

Rule

What it checks

Max file size

Size of each file, in MB

Allowed types

File extensions, such as pdf or png

Min files

Minimum number of files

Max files

Maximum number of files

These are enforced on the server for every submission. A failure returns status 422 with a message such as "Resume accepts only: pdf." in body.error.message, and the detail for each field in body.error.fields.

Allowed types are matched on the file name's extension, not on an inspection of the file's contents. Renaming a file changes its extension, so treat this rule as a way to keep submissions tidy, not as a guarantee about what a file contains. On paid plans, FormDB scans uploads for viruses and removes infected files. On the Free plan files are not scanned, so open files from strangers with the same care you would give an email attachment.

Marking the field as required means at least one file must be sent. The full rule list is in validation rules.

Where the files go

  • In the dashboard: open a submission to see its files and download them. Files are stored privately and served through signed links that expire after 7 days. The dashboard creates fresh links each time you load submissions.
  • In notification emails: files are not attached. The email states how many files were uploaded and links to the submission in FormDB.
  • In CSV exports: file fields contain the file names.
  • In webhooks and integrations: files appear as signed download links, valid for 7 days from delivery.
  • For spam: if a submission is flagged as spam, its files are discarded and not stored.

Errors worth handling

Status

Code

Meaning

402

uploads_disabled

The form's plan does not include file uploads

413

too_large

The request is over 50 MB

413

file_too_large

A file is over the plan's per-file limit

413

storage_full

The workspace's file storage is full

422

validation_failed

A file rule or another field rule failed

In each case body.error.message holds text you can show to the visitor.

Next steps

The file uploads documentation covers storage and download links in detail, and the form builder guide shows how to add a File upload field with rules. To try it with your own form, create a free account, then compare plans on the pricing page if you need more storage.

Your form can be livebefore your coffee is cold.

Create a form, paste one URL and send yourself a test. The Free plan covers 250 submissions a month, with no credit card required.