Convert a File to Base64: FileReader
To convert a file to Base64 in the browser, read it with FileReader.readAsDataURL and keep the payload after the comma. Docify writes that string to the output on Encode. Download is encoded.txt (text/plain), not a restored image or PDF. Nothing is uploaded.
File bytes are not the same as the file's name typed into a textarea. The live Base64 tool has a separate Upload file control that reads the file locally.
How to encode a file in three steps
Step 1: Stay on Encode
Choose Encode. Upload file has no MIME filter — images, PDFs, and other local files can be picked. The page does not inspect or reject types.
Step 2: Upload the file
Click Upload file and pick one file. The reader calls readAsDataURL, then takes result.split(',')[1]. On Encode that payload goes straight to the output box. You do not click Encode for this path. Text encode with btoa is unused here — see Encode text to Base64 with btoa.
Step 3: Copy or save the payload
Copy writes the payload to the clipboard. Download saves it as encoded.txt (text/plain). There is no automatic data:<mime>;base64, prefix and no binary download of the original file.
What the file path actually does
Data URL, then strip
readAsDataURL yields a string such as:
Only the part after the first comma is kept. The MIME type in the prefix is discarded. If you need a complete data URL for HTML or CSS, prepend the type yourself.
Decode mode
On Decode, the same upload writes the payload into the input box. Clicking Decode then runs decodeURIComponent(escape(atob(input))), which expects UTF-8 text. A PNG or PDF payload will typically error or look like garbage. See Decode Base64 to UTF-8 with atob.
Limits
Only one file is read (e.target.files[0]). Very large files can strain browser memory. The page does not chunk, compress, or stream to a server. This is not a way to email attachments or store files in a database for you — it only produces a text payload.
Encode a file in the browser
FileReader data URL, payload after the comma. Nothing is uploaded.
Use Base64 File Encode →FAQ
- Does converting a file upload it?
- No. FileReader.readAsDataURL runs in your browser. The page does not send the file to a server.
- How does Docify encode a file to Base64?
- Upload file reads the chosen file with FileReader.readAsDataURL, then keeps only the substring after the first comma. That is the standard Base64 payload. On Encode, that string is written straight to the output box — you do not click Encode. The input has no accept filter, so any local file can be selected.
- Is the data: prefix included?
- No. A data URL looks like data:<mime>;base64,<payload>. Docify drops everything through the comma, so you get the payload only. Add the MIME prefix yourself if you need an <img> src or CSS url.
- Can I download the original file back?
- No. Download always saves the current output as text/plain (encoded.txt on Encode, decoded.txt on Decode). There is no file-type-aware binary restore. Decode after an upload still treats the payload as UTF-8 text.