File encoding guides

Create a data URL that restores the original bytes

·

Package file bytes and a media type in a data URL. Choose Base64 for binary files or percent encoding for readable text. Check the media type.

Data URI Generator

Encode three characters two ways

The text A+B contains three UTF-8 bytes. Base64 produces QStC, yielding data:text/plain;base64,QStC. Percent encoding produces data:text/plain,A%2BB. Both restore the same three bytes. A literal plus has no special meaning inside a data URL.

RFC 2397 — The data URL scheme

Choose a media type for a file

A saved CSV can declare text/csv;charset=UTF-8 if its bytes already use UTF-8. Changing the label does not transcode a file. When its format is unknown, keep application/octet-stream. Decode the finished URL and compare the downloaded file against the source.

Check both layers when including a literal percent sign

Try the text 50%. Percent encoding represents the percent sign as %25. Copy the complete data URL, decode it, and check that the recovered text contains one percent sign. Encoding the URL as a second payload would introduce another percent-encoding layer.

Keep the intended media type with the result. An application deciding whether it accepts an inline resource can reject the data URL even when its bytes decode correctly.

Common questions

How can I tell whether the whole URL was copied?

Copy full text and Download text use the entire result, including when the visible preview is truncated.

When is percent encoding shorter?

Unreserved ASCII characters use one character each. Other bytes use three. Compare both outputs when your file is mostly ASCII text.

Sources

Put it into practice.

Related guides