Gratis å bruke, uten konto

Fil til Base64 og data-URI

Kod en fil på enheten din som Base64-tekst eller data-URI med MIME-typen. Forhåndsvis vanlige rasterbilder, kopier resultatet eller last det ned som tekst. Ingen opplasting eller konto kreves.

Én fil på opptil 2 MiB. Filen kodes på denne enheten; ingenting lastes opp.

MIME-typen hentes fra nettleserens filmetadata; den er ikke en kontroll av format eller sikkerhet. Forhåndsvisning av bilder støtter bare PNG, JPEG, GIF, WebP, BMP og AVIF. SVG-filer og dokumenter åpnes ikke i forhåndsvisningen.

Hvordan konverterer jeg en fil til Base64?

Velg én fil på opptil 2 MiB og trykk på Konverter. Kopier eller last ned data-URI-en, eller bytt til bare Base64. MIME-typen leses fra nettleseren og kan være ukjent.

Veiledning

Slik bruker du Fil til Base64 og data-URI

The File to Base64 and Data URI tool turns one file from your device into Base64 text, or into a data URI that starts with data: and the file's MIME type. Common image types also get a small preview. It works in one direction only, from file to text, and it does not decode Base64 back into a file or check what a file really contains.

Slik gjør du

  1. Press Choose a file and pick one file of up to 2 MiB from your device.
  2. Pick the output format: Data URI, which includes the MIME type, or Base64 only.
  3. Press Convert file. The text appears in the output box, with the MIME type, the file size and the output length underneath.
  4. Press Copy output, or Download text file to save it as binary-data.txt. Press Clear to start again.

Eksempler

A short text file

Du skriver inn
byte
Hello, World!
MIME-type
text/plain
Du får
Base64
SGVsbG8sIFdvcmxkIQ==
Data-URI
data:text/plain;base64,SGVsbG8sIFdvcmxkIQ==
Byteantall
13

Base64 turns every 3 bytes into 4 text characters. Thirteen bytes do not divide by 3, so the output ends with two equals signs as padding.

Kjørt med verktøyets egen kode.

The start of a JPEG file

Du skriver inn
byte
255; 216; 255
MIME-type
image/jpeg
Du får
Base64
/9j/
Data-URI
data:image/jpeg;base64,/9j/
Kan forhåndsvises som bilde
ja

Three bytes become exactly four characters and need no padding. Because the type is a common image type, the page would also show an image preview.

Kjørt med verktøyets egen kode.

A file with no known type

Du skriver inn
byte
1; 2; 3; 4
MIME-type
Du får
Data-URI
data:application/octet-stream;base64,AQIDBA==
MIME-type
application/octet-stream

If the browser gives no usable MIME type, the tool labels the data application/octet-stream, which means unknown binary data.

Kjørt med verktøyets egen kode.

A file over the size limit

Du skriver inn
Størrelse
2 MiB plus 1 byte
Du får
Resultat
refused

The limit is 2 MiB, which is 2,097,152 bytes. One byte more is refused before encoding starts, both in the page and in the encoding function.

Kjørt med verktøyets egen kode.

Når det er nyttig

  • Embed a small icon or image directly in HTML or CSS as a data URI.
  • Put a short file into a JSON or config value that only accepts text.
  • Check what Base64 looks like for a given file while learning about encodings.
  • Prepare a tiny test file to paste into an email, chat or API request.

Begrensninger

  • Only one file at a time, up to 2 MiB (2,097,152 bytes). Larger files are refused.
  • The MIME type comes from the browser's file information and is not checked against the real content. When it is missing or odd, the tool uses application/octet-stream.
  • Previews work only for PNG, JPEG, GIF, WebP, BMP and AVIF. SVG files and documents are not opened in the preview.
  • Base64 text is about one third larger than the file, and the browser needs memory for both. A 0 byte file gives an empty result.

Tips

  • Shrink or compress images before encoding, since Base64 makes them larger and slows a page.
  • Choose Base64 only if your code adds its own data: prefix, and Data URI if you paste straight into HTML or CSS.
  • Do not paste Base64 text of private files into places you do not trust. It is not encryption.

Kilder

Vanlige spørsmål

What is Base64?

Base64 is a way to write any bytes using 64 safe text characters, so a file can travel through places that only handle text. Every 3 bytes become 4 characters, with equals signs added at the end when the length is not a multiple of 3.

What is a data URI?

It is text of the form data:, then a media type, then ;base64, a comma and the encoded data. A browser can treat it like a tiny file, so it can sit inside HTML or CSS without a separate request.

Can this tool decode Base64 back into a file?

No. This tool only goes from a file to Base64 text. To turn text back into a file, you need a different decoder.

Is my file uploaded?

No. The file is read and encoded in your browser and nothing is sent to a server. The tool does not save it either. Large files do use extra memory in your browser while they are encoded.

Why does the MIME type look wrong?

The tool reads the type that your browser reports for the file, usually from its extension. It does not look inside the file, so a renamed file can carry the wrong type. Edit the data URI by hand if you need a different one.

Is Base64 a way to hide or protect a file?

No. Base64 is an encoding, and anyone can reverse it. It makes a file larger and safe for text, but it adds no secrecy. Use real encryption if you need to protect content.

Why is the output longer than my file?

Each group of 3 bytes becomes 4 characters, so the text is about 33 percent longer, plus padding. The page shows the file size and the output length so that you can compare them.

Hvordan konverterer jeg en fil til Base64?

Velg én fil på opptil 2 MiB og trykk på Konverter. Kopier eller last ned data-URI-en, eller bytt til bare Base64. MIME-typen leses fra nettleseren og kan være ukjent.

Blir filen min lastet opp eller lagret?

Nei. Den valgte filen leses og kodes i denne nettleseren. Ingenting sendes til en server eller lagres av dette verktøyet. Nettleseren trenger ekstra minne til filen og den kodede teksten.

Hva er en Base64-data-URI?

Det er tekst som begynner med data:, inneholder en MIME-type og ;base64, og deretter filens byte kodet som Base64. Den kan brukes i HTML- eller CSS-sammenhenger som støtter formatet.

Laster dette opp filen eller bekrefter den faktiske filtypen?

Nei. Kodingen skjer i nettleseren. Den viste MIME-typen hentes fra nettleserens filmetadata og verifiseres ikke mot filens byte.

Kan jeg gjøre hvilken som helst fil om til en data-URI?

De fleste filer kan representeres som Base64-tekst, men ikke alle nettsteder eller nettleserfunksjoner godtar alle MIME-typer. Dette verktøyet koder én fil på opptil 2 MiB.