Multipart Form Data Errors — File Upload HTTP Request Failures
About Multipart Form Data Errors
Fix multipart/form-data upload errors including boundary parsing failures, size limit exceeded, and content-type mismatches in HTTP file uploads. This guide covers everything you need to know about this topic, including common causes, step-by-step solutions, and answers to frequently asked questions.
Here are the key things to understand: Multipart form data is the standard encoding for HTTP file uploads using Content-Type: multipart/form-data. Each part is separated by a boundary string specified in the Content-Type header. Servers impose size limits on individual files and total request body size. Missing or malformed boundary strings cause 400 Bad Request errors. Incorrect Content-Type header (e.g., application/json instead of multipart/form-data) causes parsing failures. Understanding these fundamentals will help you diagnose and resolve this issue more effectively.
The most common reasons this occurs include: Content-Type header missing the boundary parameter required for multipart parsing. Request body exceeding server-configured maximum size (Nginx: client_max_body_size, Apache: LimitRequestBody). Client manually setting Content-Type without letting the HTTP library auto-generate the boundary. File field name in the request not matching the expected field name on the server. Identifying the root cause is the first step toward finding the right solution.
To resolve this, follow these recommended steps: Do not manually set the Content-Type header — let your HTTP client library generate it with the correct boundary. Increase server upload limits: Nginx 'client_max_body_size 50m;' or Apache 'LimitRequestBody 52428800'. Verify the form field name matches the server expectation (e.g., 'file' vs 'upload' vs 'attachment'). Check for proxy/CDN upload size limits (Cloudflare free tier limits uploads to 100MB). Use chunked uploads for large files to avoid timeout and memory issues. If these steps do not resolve the issue, consider consulting additional resources or a qualified professional.
This article is part of our HTTP Status Codes collection on Error Codes Wiki. We provide comprehensive, up-to-date information to help you find solutions quickly.
Quick Answer
Why should I not set Content-Type manually for file uploads?
The multipart boundary must be included in the Content-Type header and match the delimiters in the body. HTTP libraries like fetch, axios, and curl auto-generate this when you use FormData.
Overview
Fix multipart/form-data upload errors including boundary parsing failures, size limit exceeded, and content-type mismatches in HTTP file uploads.
Key Details
- Multipart form data is the standard encoding for HTTP file uploads using Content-Type: multipart/form-data
- Each part is separated by a boundary string specified in the Content-Type header
- Servers impose size limits on individual files and total request body size
- Missing or malformed boundary strings cause 400 Bad Request errors
- Incorrect Content-Type header (e.g., application/json instead of multipart/form-data) causes parsing failures
Common Causes
- Content-Type header missing the boundary parameter required for multipart parsing
- Request body exceeding server-configured maximum size (Nginx: client_max_body_size, Apache: LimitRequestBody)
- Client manually setting Content-Type without letting the HTTP library auto-generate the boundary
- File field name in the request not matching the expected field name on the server
Steps
- 1Do not manually set the Content-Type header — let your HTTP client library generate it with the correct boundary
- 2Increase server upload limits: Nginx 'client_max_body_size 50m;' or Apache 'LimitRequestBody 52428800'
- 3Verify the form field name matches the server expectation (e.g., 'file' vs 'upload' vs 'attachment')
- 4Check for proxy/CDN upload size limits (Cloudflare free tier limits uploads to 100MB)
- 5Use chunked uploads for large files to avoid timeout and memory issues