File to Base64

Convert any file into a Base64-encoded string.

This reads any file you choose and turns it into a Base64 text string, representing its binary contents as plain text. Unlike the image specific converter, this one takes any file type, useful for embedding a document, a font, or a small asset directly into code or a config file.

How to use it

  1. Choose any file from your device.
  2. Give it a moment to read and encode it.
  3. The Base64 string appears in the output box.
  4. Copy it with the copy button.
  5. Paste it wherever you need the file embedded as text.

When it helps

  • Embedding a small font file inside a CSS font face declaration.
  • Including a small document directly inside a JSON payload for an API.
  • Attaching file data to an email or webhook that expects text rather than a binary attachment.
  • Storing a small file directly in a database text field without a separate storage system.
  • Sharing a small file's contents as one copyable block of text.

Good to know

  • This works best for small files. Base64 adds about a third to the size, which adds up fast for anything large.
  • Keep track of the file's original type, since the data URL includes a MIME type prefix that downstream code may rely on.
  • For big files, an actual file storage or upload solution will generally work better than embedding Base64 text.
  • Check the resulting string's length before storing many files this way in a database text field, since a lot of sizeable encoded files add up quickly.
  • If you're not sure a file will be small enough to embed reasonably, check its size in your file browser first before running it through this tool.

Questions

Is there a file size limit?

No hard limit, but a very large file will produce a very long string and take a bit longer to process since it all happens in your browser.

What does the MIME type prefix mean?

The data prefix includes the detected type, like application/pdf or font/woff2, telling whatever reads the data URL what kind of file it represents.

Can I decode the string back into the original file?

In principle any Base64 data URL can be decoded back to its original file, though this tool's companion decoder is built specifically for images.

Can I encode a PDF or a Word document?

Yes, this accepts any file type your browser can read, though larger documents produce correspondingly long strings.

What's the advantage over just attaching a file normally?

Base64 lets you embed a file's data directly as text within another format like JSON, which suits certain APIs, though it's generally less efficient than a direct upload for larger files.

Does the file type affect how long encoding takes?

Not really, the main factor is file size rather than type. A small file of any type encodes quickly, while a large one takes longer regardless of format.