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 encoded text in Encode. Encoding ASCII Hello World! writes SGVsbG8gV29ybGQh on /base64/. That is the text path, not this FileReader path. The result is a text/plain Base64 dump, not a restored image or PDF. RFC 4648 §10 output foobar is Zm9vYmFy — the same bytes are MZXW6YTBOI====== on /base32/, CPNMUOJ1E8====== on /base32hex/, and 666F6F626172 on /base16/. The text path does not call String.prototype.normalize. Encoding NFC é (U+00E9) writes w6k= on /base64/. Encoding NFD e + U+0301 writes ZcyB. Compose e + U+0301 to é (U+00E9) on /unicode-normalize/. FileReader encodes file bytes as-is. 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. Try the text path with ASCII Hello World! in Encode mode — that uses the text path, not FileReader.readAsDataURL. RFC 4648 §10 output foobar → Zm9vYmFy is the same alphabet (the sample here is different). Those same bytes are MZXW6YTBOI====== / CPNMUOJ1E8====== / 666F6F626172 on /base32/, /base32hex/, and /base16/.
How FileReader differs from text encoding
This ASCII string encodes to the RFC 4648 line shown below. This is the text path, not FileReader.readAsDataURL. Upload file uses the separate FileReader path.
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. The example does not use this path — it only fills Hello World! and does not read a file.
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 result box. You do not click Encode for this path — the FileReader writes directly. 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. Encoding ASCII Hello World! on the text path writes SGVsbG8gV29ybGQh as that same text/plain dump, not a restored 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. The example never writes a data URL — it fills Hello World! as plain text.
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. The sample fills Encode mode with Hello World! for the text path. 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. The sample uses the text path and does not pick a file.
RFC 4648 output family
Hello World! is the sample; foobar is §10
The sample on /base64/ fills ASCII Hello World! and does not read a file. Encode of that output writes SGVsbG8gV29ybGQh. Encoding foobar on the same page writes Zm9vYmFy — the RFC 4648 §10 vector, also used on /base64url/ because it has no + or /. The same UTF-8 bytes are MZXW6YTBOI====== on /base32/, CPNMUOJ1E8====== on /base32hex/, and 666F6F626172 on /base16/. File encode is still a separate FileReader path.
UTF-8 Base64 is not NFC
Base64 of NFC é is w6k=; NFD e + U+0301 produces ZcyB
FileReader encodes the chosen file bytes as-is. The text path on the same page wraps the typed string as UTF-8 and does not call String.prototype.normalize. Canonically equivalent é (U+00E9, UTF-8 C3 A9) and é (e + U+0301, UTF-8 65 CC 81) therefore produce different RFC 4648 strings on that text path.
Try it with ASCII Hello World! — that is the text path, not FileReader. For Unicode normalization (e + U+0301 → é), see /unicode-normalize/.
Encode a file in the browser
FileReader data URL, payload after the comma. The example is the text path, not that FileReader path. Nothing is uploaded.
Use Base64 File Encode →FAQ
- How do I convert a file to Base64?
- Click Upload or drag a file. The tool reads it with FileReader.readAsDataURL, then extracts the Base64 payload after the comma.
- Does this tool upload my file?
- No. All conversion runs in your browser using the FileReader API. Your file never leaves your device.
- What file types are supported?
- Any file type works. The tool encodes raw bytes as Base64 regardless of format.
- Why is the result different from text encoding?
- File encoding reads raw bytes. Text encoding first converts characters to UTF-8 bytes, then encodes.
- Can I convert the Base64 back to a file?
- Yes, but you need a decoder that handles binary output. This tool's text decoder only outputs UTF-8 text.
- Is the data URL prefix included?
- No. The tool outputs only the Base64 payload. Add data:type;base64, yourself if you need a data URL.
Related
- Base64 vs Base64URL: URL-Safe Alphabet
- Encode Text to Base64: btoa + UTF-8
- Decode Base64 to UTF-8: atob
- Hex vs Base64 vs Base32: RFC 4648 Encodings
- RFC 4648 Base32 vs Base32hex: Alphabet and Sort Order
- Live tool: Base64 encoder / decoder · Base32 encoder · Base32hex encoder · Base16 encoder · Unicode NFC / NFD