What is multipart/form-data?

multipart/form-data is the encoding a form must use to send files: each field and file travels as its own part of the request.

By default a form is sent as one line of name=value pairs, which cannot carry a file. With enctype="multipart/form-data" the browser splits the request into parts, one per field, and a file part carries the file's bytes, name and type.

If you forget the attribute on a form with a file input, only the file's name is sent. The upload appears to work and the file never arrives.

When sending with JavaScript, pass a FormData object as the body and do not set the Content-Type header yourself. The browser sets it, including a boundary marker that separates the parts.

html
<form action="https://formtango.com/f/YOUR_FORM_ID" method="POST" enctype="multipart/form-data">
  <input type="file" name="attachment">
  <button type="submit">Upload</button>
</form>

Related