File to Base64 Converter
Convert file to Base64 in the browser: choose a ZIP, DOCX, PDF, audio file, or any other local file. This File to Base64 converter copies the result as a plain string or data URI, and ZIP to Base64 and DOCX to Base64 work the same way. The panel shows the MIME type, original size, and the ~33% overhead before you copy, which helps when a max file size Base64 limit applies.
In WeChat, downloads and image copy may be blocked. If a button does not respond, tap ··· in the top-right corner and choose Open in Browser.
File
Drop a file here or browse. Max 100 MB. Files are read locally and never uploaded.
- File
- base64box-sample.svg
- MIME type
- image/svg+xml
- Source size
- 2.7 KB
- Base64 size
- 3.6 KB · 3,656 chars
- Overhead
- +33%
Selected images
File to base64 reads any file from disk — a ZIP archive, a DOCX report, an audio clip or an unusual binary — and returns its bytes as a Base64 string or a wrapper for JSON, XML or HTML, encoding the file in your browser tab. Nothing is uploaded, and no copy is written to disk.
It is useful when a JSON API has to carry a binary attachment, when a database column stores files as text, or when a test fixture needs a small binary embedded in source code. Because the page does not filter by extension, an encoded result exists even for formats the browser cannot preview, which is exactly the case when a checksum or a size count matters.
How to use
- Choose the file. Drop it on the panel or browse. Any extension is accepted; the single cap is 20 MB, because the bytes are read into memory. The details table then shows file name, MIME type, source size and the encoded size.
- Pick a wrapper. Copy as offers Data URI, Plain Base64, HTML link, JSON and XML. Data URI needs a MIME type to be useful; JSON and XML include the name and size, which is safer for an attachment record.
- Copy or download. Copy output takes the full file to base64 string, and Download saves
{name}-base64.txt. If the browser reports no MIME type, the value is labelledapplication/octet-streamand should be stored with an explicit type elsewhere.
Archives, Office files and unknown types
A Base64 string carries bytes, not metadata. These notes cover the places where the missing metadata changes how the output should be used.
ZIP to base64 and the PK header
A ZIP archive starts with 50 4B 03 04, which encodes to UEsDB at the beginning of the string. A zip to base64 value can therefore be recognized before decoding, and a string starting any other way is not a ZIP even if the filename says .zip. Keep archives under 20 MB; a 15 MB zip becomes 20 MB of characters and is already at the comfortable limit for a JSON field. Encoding does not compress further either, because the archive is already compressed and the only growth is Base64 overhead.
DOCX to base64 when the type matters
A DOCX file is a ZIP container too, so its encoded form also starts with UEsDB. What changes is the MIME type: browsers usually report application/vnd.openxmlformats-officedocument.wordprocessingml.document, and that long label is what a data URI must carry for Word to open it. Dropping the type and using application/octet-stream leaves the file valid but harder to open for the recipient. A 2 MB DOCX becomes about 2.7 MB of text, and the original can be rebuilt byte for byte when the type and name are kept.
Convert file to base64 without a known extension
When the browser cannot identify a file, the MIME row shows application/octet-stream. The bytes are still correct, but the data URI becomes noncommittal. For a proprietary format, choose Plain Base64 and document the extension next to the value, or use the JSON wrapper, which records the name and byte size so the receiver can reconstruct the file. Files without any signature, such as a .bin firmware image, are still valid input; only the label is uncertain.
FAQ
What is the max file size base64 can handle here?
20 MB per file. That limit is checked before reading, because the browser holds the bytes and the text in memory at the same time. At the cap, a file to base64 output reaches about 27 MB of characters, which is already large for a JSON field.
Is my file uploaded when I encode it?
No. The file is read locally through the File API and encoded in the tab. Nothing is transmitted, cached on a server or logged, so private archives and internal documents can be converted without a security review.
Why is the MIME type application/octet-stream?
The browser could not identify the extension. The bytes are still encoded correctly, but a data URI with that type tells the receiver nothing. Store the real extension beside the value, or use the JSON wrapper, which records the file name and size.
Why does the encoded output fail at the size limit?
A file over 20 MB stops with “File is too large for browser-side processing.” Split the archive, compress the payload, or encode it with a command-line tool. The limit exists because a copy of the bytes and a copy of the text are both kept while the box fills.
Can I decode the string back into a file?
Yes, with a decoder that knows the type. For images use Base64 to Image, for documents use Base64 to PDF, and for anything else keep the extension next to the value. A bare file to base64 string does not contain its own filename, so record it separately.
Related tools
PDF to Base64 Converter narrows the same encoder to documents and adds a data URI prefix for application/pdf. Image to Base64 Converter handles pictures with resizing and quality controls that a generic file does not expose. Base64 to PDF turns a document string back into a file. A file to base64 value from this page can be decoded anywhere the type is known, so keep the extension beside it at all times.