multipart/form-data MIME Type — File Uploads, FormData & Examples
An encoding for HTML forms that include file uploads. Parts are separated by a unique boundary string. Each part can have a different Content-Type, enabling mixed text fields and binary file uploads in a single request.
Used For
- File upload forms
- Avatar/profile image uploads
- Document submission
- Bulk import forms
HTTP Header Example
POST /upload HTTP/1.1
Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryABC
------WebKitFormBoundaryABC
Content-Disposition: form-data; name="username"
Alice
------WebKitFormBoundaryABC
Content-Disposition: form-data; name="avatar"; filename="photo.jpg"
Content-Type: image/jpeg
[binary JPEG data]
------WebKitFormBoundaryABC--Code Examples
// HTML form with file upload
<form method="POST" action="/upload" enctype="multipart/form-data">
<input type="text" name="username" />
<input type="file" name="avatar" accept="image/*" />
<button type="submit">Upload</button>
</form>
// Fetch API with FormData
const formData = new FormData()
formData.append('username', 'Alice')
formData.append('avatar', fileInput.files[0])
// Do NOT set Content-Type manually — browser adds boundary automatically
await fetch('/upload', { method: 'POST', body: formData })
// Express with multer
import multer from 'multer'
const upload = multer({ dest: 'uploads/' })
app.post('/upload', upload.single('avatar'), (req, res) => {
console.log(req.file) // uploaded file
console.log(req.body) // text fields
})Related MIME Types
Frequently Asked Questions
What is the multipart/form-data MIME type?
An encoding for HTML forms that include file uploads. Parts are separated by a unique boundary string. Each part can have a different Content-Type, enabling mixed text fields and binary file uploads in a single request.
When should I set Content-Type: multipart/form-data?
Set Content-Type: multipart/form-data on HTTP responses that contain Multipart Form Data data. File upload forms.
What file extensions use multipart/form-data?
multipart/form-data is a format type rather than a file extension — it's identified by its content structure.
What happens if I serve this with the wrong Content-Type?
Browsers use the Content-Type header to decide how to handle the response. Serving multipart/form-data content with an incorrect MIME type can cause browsers to display it incorrectly, refuse to execute it (scripts), or prompt an unintended download. Modern browsers respect X-Content-Type-Options: nosniff and will not attempt to auto-detect the type.
