Content-Type for File Upload with Multiple Files
Configure the Content-Type header for uploading multiple files with multipart/form-data. Covers nested part headers and filename handling.
Form Submissions
Detailed Explanation
Multiple File Upload
When uploading multiple files in a single request, each file becomes a separate part within the multipart/form-data body, each with its own Content-Type and filename.
The Header Value
Content-Type: multipart/form-data; boundary=----FormBoundary7MA4YWxkTrZu0gW
Body Structure with Multiple Files
------FormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="files"; filename="report.pdf"
Content-Type: application/pdf
[PDF binary data]
------FormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="files"; filename="photo.png"
Content-Type: image/png
[PNG binary data]
------FormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="description"
Quarterly report and cover photo
------FormBoundary7MA4YWxkTrZu0gW--
Per-Part Content-Type
Each file part has its own Content-Type header indicating the file's media type. This is separate from the top-level Content-Type of the request. Common per-part types:
| File Type | Part Content-Type |
|---|---|
application/pdf |
|
| PNG | image/png |
| JPEG | image/jpeg |
| CSV | text/csv |
| ZIP | application/zip |
| Generic | application/octet-stream |
Filename Encoding
For filenames with non-ASCII characters, use RFC 5987 encoding:
Content-Disposition: form-data; name="file"; filename*=UTF-8''%E3%83%AC%E3%83%9D%E3%83%BC%E3%83%88.pdf
curl Example
curl -X POST \
-F "files=@report.pdf;type=application/pdf" \
-F "files=@photo.png;type=image/png" \
-F "description=Quarterly report" \
https://api.example.com/upload
Use Case
Use this when building file upload endpoints that accept multiple files, such as document management systems, image galleries, or email attachment APIs.