Code & Media

Data URI Converter

Convert a file to a data URI and back, with a live size estimate.

  • Draft kept in this tabYour draft is kept in this tab's session storage and cleared when the tab closes.
  • Runs in your browserProcessing happens in this page. No application server receives your input.
Load sample
More options

Source text

Data URI

Encoded 23 B
Direction
Encode to data: URI
Media type
text/plain
Encoding
Base64 (;base64)
Source size
0 B
Estimated encoded size (~4:3)
23 B (23 bytes)
Actual encoded size
23 B (23 bytes)
Execution
In-page
data:text/plain;base64,

What this tool does

Converts a binary file or UTF-8 text into an RFC 2397 data: URI (Base64 or percent-encoded) and decodes data: URIs back into downloadable files, reporting the ~4:3 Base64 expansion before and after encoding without any network transmission.

Conversion & safety rules

  • Binary or text source with Base64 enabled (;base64): emits data:<mediaType>;base64,<payload> and reports exact encoded byte count alongside the ~4:3 estimate.
  • UTF-8 text source with Base64 disabled: emits an RFC 3986 percent-encoded data:<mediaType>,<payload> URI.
  • Missing media type: defaults to text/plain;charset=US-ASCII per RFC 2397 rather than guessing.
  • Reverse direction (Decode from data: URI): validates the scheme, comma delimiter, and Base64 or percent-encoded payload, returning the decoded Blob, mediaType, inert UTF-8/hex preview, and local download.
  • Invalid or oversized input: rejects malformed URIs or corrupt Base64 payloads with MalformedDataUri and sources above 8.0 MB with InputTooLarge without emitting truncated output.

Operational limits & execution

Maximum source size: 8.0 MB (InputTooLarge above cap). Sources below 1.0 MB run in-page; files at or above 1.0 MB run in codegen.worker.ts ('data-uri') with cooperative cancellation. A data: URI is never fetched or executed.

Worked example

Input:

the three bytes `abc` with media type `text/plain`

Expected output:

data:text/plain;base64,YWJj

Scope: this covers the page itself. Your browser, operating system, clipboard, downloads, extensions, and crash recovery may keep copies, and a compromised site origin would not be protected.