How can an API request upload a file, and can the file be sent together with other data?
Answer
An endpoint can accept a raw binary body with a specific media type or application/octet-stream. When a file must be sent together with text fields or metadata, multipart/form-data is the usual HTTP representation: each part has its own Content-Disposition and optional Content-Type, so one part can be the file and another can be text or JSON metadata. Base64 inside JSON is possible but adds size and processing overhead. Some systems instead issue a pre-signed storage URL and persist metadata separately.
Strong answer includes
- raw binary versus multipart/form-data
- file and metadata can coexist as multipart parts
- base64 and pre-signed upload trade-offs
Practical example
A profile endpoint accepts displayName and avatar in one multipart request. The tester verifies the text part, filename, image Content-Type, zero-byte and oversized files, and that another user cannot later download the uploaded object.