How to Use a Base64 PDF in a JSON API Request
Learn how to structure a JSON payload with a Base64-encoded PDF, send it from a client, and decode it back into a file on the server.
- base64 pdf api
- base64 pdf json
- send pdf in api request
- decode base64 pdf server
- pdf me
Why APIs Encode Files as Base64
REST and JSON APIs are built around text, not raw binary, so there is no native way to drop a PDF's bytes straight into a JSON field. Encoding the file as Base64 first turns it into a string, which JSON handles like any other text value.
If you have not converted a file yet, the PDF to Base64 guide covers the conversion step itself.
Structuring the Request Body
A typical request pairs the encoded string with a few metadata fields: one field — often named file, document, or content — holds the Base64 text, a filename field carries the original file name, and a contentType or mimeType field set to application/pdf tells the receiver how to interpret the bytes once decoded.
Keep the encoded field as a single, unbroken string. Line breaks or extra whitespace inserted by an editor or a copy-paste step will corrupt the value before it ever reaches the server.
Sending the Request
Most HTTP clients — fetch in the browser, a server-side HTTP library, or a tool like curl — send the JSON body the same way they would send any other payload, as long as the Content-Type header is set to application/json. The Base64 field is just a long string inside that body.
Watch the total request size: the encoded PDF is part of the JSON, so a large attachment increases the body size directly, and some API gateways or reverse proxies enforce a maximum request size.
Decoding on the Server
Most server-side languages include a built-in Base64 decoder. Decoding turns the string back into the exact original bytes, which the server can then write to disk, store in a database, forward to another service, or stream back to a client.
If the decoded file will not open as a valid PDF, check for a stray data URI prefix or copy-paste corruption — see common PDF to Base64 problems.
When to Use a File Upload Instead
For large PDFs, frequent uploads, or files that need to be streamed rather than held entirely in memory, a multipart file upload or a direct upload to storage is usually a better fit than embedding the file in JSON. Base64 in JSON works best for small to medium files moved occasionally — certificates, signed forms, short reports.