File encoding guides

Recover a file from a data URL

·

Restore a file from the payload of a data URL. Paste the complete data URL or select a local UTF-8 text file containing one. Enter a download filename.

Data URI to File

Recover four bytes from a percent-encoded URL

Paste data:application/octet-stream,%00%FF%23+. The payload decodes to the hexadecimal bytes 00 FF 23 2B. Name the download sample.bin. A hex viewer should show four bytes, even though the result has no valid UTF-8 text preview.

RFC 2397 — The data URL scheme

Separate the media type from the content

A comma ends the header. A final ;base64 marker selects Base64 decoding. With data:,hello the default media type is text/plain;charset=US-ASCII. The label describes the source’s claim. Inspect the contents before assigning an extension to unfamiliar bytes.

Check the payload before choosing a filename

A data URL can label four arbitrary bytes as text, an image, or an application file. Decode the bytes and inspect their signature or compare a trusted digest before choosing an extension. Renaming the result only changes its name.

For a text payload, compare the character encoding with the source application. Four UTF-8 bytes can represent fewer than four displayed characters, so character counts are a poor check of byte fidelity.

Common questions

What happens to a hash in a data URL?

A literal hash begins the URL fragment. Encode a hash belonging to the file as %23.

Why can a file download without a text preview?

Binary files may contain byte sequences outside UTF-8. The download preserves those bytes.

Sources

Put it into practice.

Related guides