QA
Beginner LevelREST APIs & Web Services

How do multi-part form uploads (multipart/form-data) work in REST APIs?

❓ Interview Prompt: Explain `multipart/form-data` MIME encoding, boundary separators, file streaming, and uploading binary files with metadata.

Uploading binary files (images, PDFs) along with JSON metadata in a single HTTP request uses 'multipart/form-data':

How It Works:

1
The 'Content-Type' header specifies a unique boundary string: 'Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxk'.
2
The request body is divided into parts separated by this boundary string.
3
Each part contains its own headers ('Content-Disposition: form-data; name="avatar"; filename="photo.png"', 'Content-Type: image/png') followed by raw binary bytes.

Code Implementation Example

http
POST /api/v1/users/42/avatar HTTP/1.1
Host: api.example.com
Content-Type: multipart/form-data; boundary=--Boundary123

--Boundary123
Content-Disposition: form-data; name="description"

Profile Picture
--Boundary123
Content-Disposition: form-data; name="file"; filename="avatar.jpg"
Content-Type: image/jpeg

<binary JPEG data bytes...>
--Boundary123--
💡Multipart form data HTTP request carrying metadata and binary image payload.
🎯 Interview Key Takeaway

Use multipart/form-data with boundary strings to upload binary files alongside text metadata in HTTP requests.

#Multipart#File Upload#HTTP Payload#Beginner
Back to all REST APIs & Web Services Questions→

More REST APIs & Web Services Interview Questions

Beginner LevelREST APIs & Web Services

What is HTTP Method Idempotency and how do you implement Idempotency Keys for REST APIs?

Beginner LevelREST APIs & Web Services

What are standard HTTP Status Codes (200, 201, 204, 400, 401, 403, 404, 409, 429, 500, 503)?

Beginner LevelREST APIs & Web Services

What are HTTP Verbs (GET, POST, PUT, PATCH, DELETE) and when to use PUT vs PATCH?