Browser troubleshooting

Account for Base64 copies during file processing

Base64 represents three input bytes with four output characters before padding details. Converting a large file into Base64 can therefore increase payload size and create additional in-memory copies.

Worked example

Browser console example · use a disposable page on your own site

const bytes = 3 * 1024 * 1024;
const base64Characters = 4 * Math.ceil(bytes / 3);
console.log(base64Characters);
console.log(base64Characters / bytes);

How it works

The formula predicts encoded character count for ordinary Base64. In a browser workflow, the original bytes, intermediate strings, and final data URL can coexist. This can matter when previewing or uploading a large file even before parsing its contents.

Limits and mistakes

JavaScript string storage and browser optimizations determine actual memory use, so the character-count expansion is not an exact heap multiplier. Base64 is not required merely to display a selected file; an object URL may avoid that conversion.

Check the result

Expect 4194304 and about 1.3333. Compare a representative object-URL workflow with a Base64 workflow using the same file and the same measurement scope.

Sources

Reference documentation for the behavior used in this guide: