Logo

File to Base64

Encode any file type to Base64 or a Data URI — free, instant, nothing uploaded

Upload any file

Drag & drop or click to upload

PDF, DOCX, ZIP, fonts, audio, video — any type at all

Your file never leaves this browser. There is no upload and no server.

Output

The payload only — for APIs, config files, and database columns that add their own header.

Any File. Not Just Images.

Your API wants a PDF as a string. Or the config file needs a font inlined. You search for a converter and every result only takes images. This file to Base64 encoder takes whatever you have.

Documents, archives, fonts, audio, video, certificates. Drop it in, pick raw Base64 or a Data URI, copy the result.

Nothing uploads. Once this page has loaded you can disconnect your network and it still works.

How to Convert a File to Base64 String Output

  1. Compress first, if the file is text. CSV, SQL dumps and logs shrink hugely when zipped.
  2. Drop the file in. Any type at all — there is no filter.
  3. Read the panel. Detected MIME type, character count, and the exact growth percentage.
  4. Pick your output. Raw Base64 or a complete Data URI.
  5. Copy it. One click.

Skip step one for anything already compressed. PDFs, JPEGs, MP4s and ZIPs have had the redundancy squeezed out already, so zipping again adds a header and saves nothing.

Where File to Base64 Encoding Actually Gets Used

Four situations account for most of the traffic to this page:

  • JSON API payloads. REST endpoints that accept a document but only speak JSON.
  • Config and secrets. Kubernetes secrets and CI variables that must hold a certificate on one line.
  • Email attachments. MIME has encoded every attachment this way since the 1990s.
  • Embedded assets. Fonts and icons inlined so a single HTML file works offline.

A caveat on the first one. Payload limits bite faster than people expect — AWS API Gateway caps request bodies at 10 MB, and Base64 adds a third before the request leaves. In our experience this is the most common reason a working upload suddenly fails in production.

Encoding an image instead? The image to Base64 converter adds CSS and HTML output formats this page does not.

Raw Base64 or a File to Data URI Conversion?

Same bytes, different wrapper. Picking wrong is the most frequent mistake we see.

OutputLooks likeUse it for
Raw Base64JVBERi0xLjQKJc...APIs, database columns, config files — anything that adds its own header
Data URIdata:application/pdf;base64,JVBERi0...Browsers, CSS, HTML, download links

The rule of thumb: if a browser will read it, use the Data URI. If code will read it, use raw.

Handing a Data URI to a server library is the classic bug. Most decoders expect the payload only and choke on the data: prefix, then report an unhelpful parse error.

Encoding a PDF to Base64 Without Corrupting It

PDFs are the single most common file people bring here, and they are also the easiest to break. Three things go wrong:

  • Line wrapping. Command-line tools wrap at 76 characters. Strip the breaks before pasting into JSON.
  • Double encoding. If the source was already Base64, encoding again produces a file that opens blank.
  • Truncation. Copying from a terminal that clipped the output loses the end of the file.

A decoded PDF that opens to a blank page almost always means double encoding. The Base64 to file decoder will show you what the string really contains.

The MIME Type Gap Most Tools Ignore

Browsers do not know every extension. Drop in a .woff2, a .7z, or a .env and many report an empty type.

An empty type produces data:;base64,, which no browser will render and most parsers reject. Plenty of converters emit that and say nothing.

We fill in the correct type from the extension and tell you in the panel when we have done it. It is a small thing that saves a confusing hour.

The honest limit: we are guessing from the extension, not the contents. A file renamed to .zip will be labelled as a zip whatever is actually inside it.

Privacy and What Base64 Is Not

The file never leaves your browser. There is no upload, no queue, and no temporary storage, so it is safe for contracts, keys, and unreleased assets.

But encoding is not protection. Base64 is reversible by anyone in one click — it exists to make binary data survive text channels, nothing more.

We say this because we still see Base64 used to "hide" API keys in config files. It hides nothing. If it needs to be secret, encrypt it with our text encryption tool instead.

For plain text rather than files, the Base64 encoder and decoder handles UTF-8 correctly, including emoji.

Frequently Asked Questions

My browser reports no type for .zip or .woff files. Does that break the output?

+
It would, and this is why we patch it. An empty type produces data:;base64, which no browser will accept. We map the extension to the correct MIME type and tell you when we have done it.

Why does the base64 command in my terminal produce a different string?

+
It wraps at 76 characters by default, following the MIME spec from RFC 2045. The characters match ours exactly, only the line breaks differ. Use base64 -w 0 on Linux to get one unbroken line.

Can I encode a whole folder?

+
Not directly — Base64 works on a single stream of bytes, and a folder is not one. Zip the folder first, then encode the archive. That is what every deployment pipeline does under the hood.

Does encoding preserve file permissions or the modified date?

+
No. Base64 captures the contents and nothing else, so the executable bit, ownership, and timestamps are all lost. Wrap the file in a tar or zip archive first if that metadata matters.

Do I need to escape the string before putting it in JSON?

+
Standard Base64 uses only letters, digits, plus, slash, and equals, and none of those need escaping in JSON. The one thing to watch is line breaks — if your source wrapped the output, strip them first.

Why does my API reject a Base64 payload that looks fine?

+
Payload size limits catch people here. AWS API Gateway caps request bodies at 10 MB and Lambda is smaller still, and Base64 adds a third before the request is even sent. Upload to storage and pass a reference instead.

Should I Base64 a PEM certificate?

+
Usually not, because it already is Base64. A PEM file is Base64 wrapped in BEGIN and END markers, so encoding it again just doubles the size. Strip the markers and use the inner block if a system wants raw Base64.

Why is my DOCX identified as a ZIP archive?

+
Because it genuinely is one. DOCX, XLSX, PPTX, EPUB and JAR are all ZIP containers with a particular folder layout inside. The first four bytes are identical, so byte-level detection sees ZIP unless it looks deeper.

Does this work with no internet connection?

+
Once the page has loaded, yes. Encoding uses the browser FileReader API and never contacts a server, so you can pull the network cable and it keeps working. That is also why nothing you encode can leak.

Should I compress the file before encoding it?

+
Only if it is not already compressed. Text, CSV, and SQL dumps shrink dramatically when zipped first. PDFs, JPEGs, MP4s and ZIPs are compressed already, so a second pass adds overhead and saves nothing.

The Short Version

Drop the file, pick your output, copy it. Converting a file to Base64 works on any type here, and the MIME header is filled in for you.

Watch the size. A third is added to everything, and payload limits arrive sooner than you think.

Related Tools You Might Like

Advertisement