๐๏ธ File to Base64 Chunk Encoder โ Split Any File into Manageable Encoded Pieces
The File to Base64 Chunk Encoder converts any binary or text file โ PDFs, ZIPs, images, executables, databases โ into Base64-encoded output split into configurable chunks. This solves a classic problem in modern software development: sending large binary files over text-based channels (REST APIs, email, config files, message queues) that impose limits on string length, line width, or payload size.
Why Chunk Instead of One Long Base64 String?
A single Base64 string for a 10 MB file produces roughly 13.3 MB of text โ a single continuous blob that many systems simply refuse to process. Common scenarios where chunking is essential:
- JSON API payloads โ many frameworks impose a default body size limit (often 1 MB โ 10 MB). Chunking lets you stream file data in multiple smaller requests.
- Email MIME attachments โ RFC 2045 requires Base64 lines to be at most 76 characters and recommends splitting large payloads into parts.
- Configuration files โ embedding large binary assets (certificates, embedded fonts, compiled WASM modules) in YAML/TOML/ENV files requires manageable line lengths that editors and parsers can handle.
- Message queue systems โ platforms like SQS, Kafka, and Pub/Sub enforce per-message size caps (typically 64 KB โ 256 KB). Chunking lets you reliably transmit arbitrarily large files.
The Base64 Encoding Ratio
Base64 encodes every 3 input bytes into 4 ASCII characters, producing a consistent overhead of exactly 33.33%. A 1 MB file becomes approximately 1.37 MB of Base64 text. This is unavoidable โ it is a fundamental property of the encoding scheme, not a limitation of this tool.
๐ Key Size Formulas
| Metric | Formula |
|---|---|
| Encoded size per chunk | ceil(chunkBytes / 3) ร 4 chars |
| Total encoded size | ceil(fileSize / 3) ร 4 bytes |
| Overhead percentage | (encodedSize / originalSize โ 1) ร 100 |
| Number of chunks | ceil(fileSize / chunkBytes) |
Output Formats Explained
Plain Text
All chunks are concatenated with a configurable delimiter string. Escape sequences like \n and \t are interpreted so you can use multi-line delimiters such as \n---CHUNK---\n. This format works with any text processing pipeline.
JSON Array
Produces a structured JSON object with fileName, mimeType,totalChunks, and a chunks array โ each element containing one raw Base64 string. This format is ideal for REST API payloads, localStorage, and IndexedDB storage.
{
"fileName": "archive.zip",
"mimeType": "application/zip",
"totalChunks": 8,
"chunks": [
"SGVsbG8gV29ybGQhI...",
"dGhpcyBpcyBjaHVua...",
...
]
}MIME Parts
Each chunk is wrapped in RFC 2045-compliant headers including Content-Type, Content-Transfer-Encoding: base64, and a Content-Disposition header with the chunk index. This format is directly usable in multipart email bodies and HTTP multipart requests.
PEM Blocks
Each chunk is wrapped in -----BEGIN FILE CHUNK n/N----- and -----END FILE CHUNK n/N----- delimiters, following the PEM (Privacy Enhanced Mail) convention used in SSL/TLS certificates, SSH keys, and security tooling configuration.
Standard vs URL-safe Base64
Standard Base64 uses the characters + and /, which have special meaning in URLs and HTTP headers. URL-safe Base64 (RFC 4648 ยง5) replaces them with - and _, making the output safe for use in query parameters, Authorization headers, JWTs, and cookie values without requiring percent-encoding.
Reassembling Chunks
To reconstruct the original file from chunks, decode each Base64 string back to bytes and concatenate them in index order. Below are quick snippets:
JavaScript (browser / Node.js)
const chunks = ["SGVs...", "bG8g..."];
const bytes = chunks.flatMap(c => [...atob(c)].map(ch => ch.charCodeAt(0)));
const blob = new Blob([new Uint8Array(bytes)], { type: "application/octet-stream" });Python
import base64
chunks = ["SGVs...", "bG8g..."]
data = b"".join(base64.b64decode(c) for c in chunks)
open("output.bin", "wb").write(data)Privacy & Security
All encoding happens entirely in your browser using the native FileReader API and btoa(). SHA-256 hashes are computed via the browser's Web Crypto API (SubtleCrypto). Your file data is never uploaded to any server โ it remains on your device throughout the entire process.
Note: SHA-256 hashing requires a secure context (HTTPS or localhost). The tool will silently skip hashing if SubtleCrypto is unavailable.