A virtual teacher who reveals to you the great secrets of Base64

File to Base64

Encode file to Base64 online and embed it into any text document such as HTML, JSON, or XML. The fact is that if you do not convert binary to Base64, you won’t be able to insert such data into text files, because binary characters will corrupt text data. It is important to remember that the size of Base64 encoded files increases by 33%. Please note that the file to Base64 encoder accepts any file types with a size of up to 50 MB. If you are looking for the reverse process, check Base64 to File.


How to convert file to Base64 online

  1. Select a local file from your computer.
  2. If necessary, select the desired output format.
  3. Press the “Encode file to Base64” button.
  4. Download or copy the result from the “Base64” field.

Output formats

If you do not know what output format you need, check the following examples to see how will look the result of the same Base64-encoded file formatted in each of the available formats (as an example file I use a gzipped text file):

Plain text:
H4sICPsdulsCAHJlYWRtZS50eHQAC0/NSc7PTVUoyVdISixONTPRSy8tKlUEAPCdUNYXAAAA
Data URI:
data:application/gzip;base64,H4sICPsdulsCAHJlYWRtZS50eHQAC0/NSc7PTVUoyVdISixONTPRSy8tKlUEAPCdUNYXAAAA
HTML Hyperlink:
<a href="data:application/gzip;base64,H4sICPsdulsCAHJlYWRtZS50eHQAC0/NSc7PTVUoyVdISixONTPRSy8tKlUEAPCdUNYXAAAA"></a>
JavaScript Popup:
window.onclick = function () {
  this.open("data:application/gzip;base64,H4sICPsdulsCAHJlYWRtZS50eHQAC0/NSc7PTVUoyVdISixONTPRSy8tKlUEAPCdUNYXAAAA");
};
JSON:
{
  "file": {
    "mime": "application/gzip",
    "data": "H4sICPsdulsCAHJlYWRtZS50eHQAC0/NSc7PTVUoyVdISixONTPRSy8tKlUEAPCdUNYXAAAA"
  }
}
XML:
<?xml version="1.0" encoding="UTF-8"?>
<root>
  <file mime="application/gzip">H4sICPsdulsCAHJlYWRtZS50eHQAC0/NSc7PTVUoyVdISixONTPRSy8tKlUEAPCdUNYXAAAA</file>
</root>

If I missed an important output format for Base64-encoded files, please let me know — I would love to implement it.

Comments (55)

I hope you enjoy this discussion. In any case, I ask you to join it.

  • JPEREZ,
    PRUEBA GENERANDO ARCHIVO
    • Mogami,
      Esto es una prueba
  • Donaltleer,
    hi

    help us
    • Administrator,
      Hello! I would like to help you, but I need to know some details about your issue.
      • Ranya_t,
        I need to read my files I lost my key and files on myy old phone, so I had these copys saved
    • zaffar,
      i am not able to copy code .,..showing failed to copy
      • Someone,
        just press ctrl+c after click copy
    • Peter,
      what's goodie my boi? May I assist you in any way? I would really love to help you but unfortunately Im currently not exactly sure how. PLEASE let me know!
  • seth,
    well this is delightfully useful. thank you
    • Administrator,
      Thank you sir for your kind words.
  • Jan_Girke,
    Thanks for the page :)
  • Khayri_RR_Woulfe,
    This converter works for webfonts (*.woff2) perfectly.
  • Volker,
    Hello Base64 Guru,

    I really like this page. Thanks for the free encoding and decoding tool :)

    Best regards

    Volker
  • Cody,
    I was wondering if you provided an api or code to do this. Thanks!
  • Mosab,
    is that a good result?
  • Evan,
    I got a 413 request entity too large. What is the max size?
  • sallin,
    Test xml file
  • Carol,
    Hi, I am new to base64 encoded. using code below is not returning the same result when I am converting a docx file. I got more characters in my results. May I know what did I missed ?

     $sourceString = Get-Content -Path $file.Fullname -raw 
     $arB = [System.Text.Encoding]::UTF8.GetBytes( $sourceString ) 
     [System.Convert]::ToBase64String( $arB ); 
  • ThankYou,
    Thank you for this page. It really helps
  • Sarabjeet,
    Hello

    When I am using your encoder and decoder I get same output but when I use Java encoder decoder, I get different outputs:

    try {
    BufferedReader reader = new BufferedReader(new FileReader("C:\\Users\\Sarabjeet Singh\\Downloads\\rki-ssl-testing\\testing\\rki-ssl.p12"));
    StringBuilder stringBuilder = new StringBuilder();
    String line = null;
    String ls = System.getProperty("line.separator");
    while ((line = reader.readLine()) != null) {
    stringBuilder.append(line);

    }
    // delete the last new line separator
    // stringBuilder.deleteCharAt(stringBuilder.length() - 1);
    reader.close();

    String content = stringBuilder.toString();

     String encodedString = Base64.getEncoder().encodeToString(content.getBytes());
     byte[] decoder = Base64.getDecoder().decode(encodedString.getBytes());
        //String encodedString = new String(encoded);
     File file = new File("C:\\Users\\Sarabjeet Singh\\Downloads\\rki-ssl-testing\\testing\\converted_as_p12_from_code.p12");    
     try ( FileOutputStream fos = new FileOutputStream(file); ) {
          // To be short I use a corrupted PDF string, so make sure to use a valid one if you want to preview the PDF file
          //String b64 = "JVBERi0xLjUKJYCBgoMKMSAwIG9iago8PC9GaWx0ZXIvRmxhdGVEZWNvZGUvRmlyc3QgMTQxL04gMjAvTGVuZ3==";

          fos.write(decoder);
          System.out.println(" File Saved");
        } catch (Exception e) {
          e.printStackTrace();
        }
    } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }


    could you help me
  • anon,
    Neat tool! Thanks.
  • Kelatte,
    It helps me a lot! Thank you!
  • Jose,
    hi, i need to convert a .cer file to base64 format
    i have an example

    but not the same that results in this page...
    the example has '=' at the end

    what can i do?

    thanks
  • Sub_To_Mad-Love,
    Hey! how can i convert js file to base64?
  • Someone,
    Hi, can I encode VERY LARGE files (1TB+)? Would it work or is it just a waste of time?

    [UPDATED: ]
    After trying to encode an 1 GB file:(

    This site can’t be reachedbase64.guru unexpectedly closed the connection.

    Try:
    Checking the connection
    Checking the proxy and the firewall
    Running Windows Network Diagnostics
    ERR_CONNECTION_CLOSED
    Check your Internet connection
    Check any cables and reboot any routers, modems, or other network devices you may be using.
    Allow Chrome to access the network in your firewall or antivirus settings.
    If it is already listed as a program allowed to access the network, try removing it from the list and adding it again.
    If you use a proxy server…
    Check your proxy settings or contact your network administrator to make sure the proxy server is working. If you don't believe you should be using a proxy server: Go to the Chrome menu > Settings > Show advanced settings… > Change proxy settings… > LAN Settings and deselect "Use a proxy server for your LAN".
    • Administrator,
      Sorry, but for such large files you have to use a local solution.
      • Drak687,
        Help me do a local solution Help me i try to do A file to i64 to run it on ida
  • imran,
    Hi buddies,
    I have an base64.dat file,
    And file contains private keys of my bitcoin wallet.
    Someone please help me to decode this file.
    • Steve,

      $file = Get-Content -Path base64.dat
      [System.Convert]::FromBase64String(($file)) | Set-Content output.txt -Encoding utf8
  • Mein-Reset,
    Thank you, i'm happy right now
  • Jeremy,
    Thank you for this tool!
  • joseph,
    cGxlYXNlIGhlbHAgbWUgaW0gdHJhcHBlZCBpbiBzb21lIHBlcnNvbnMgYmFzZW1lbnQNCg==
    • Anon,
      ZG9uJ3QgbW92ZSwgaSdtIG9uIG15IHdheQ==
  • steve-hollis,
    this worked amazingly well at converting a font to data-uri - to get around a CORS scripting issue that was plaguing me for ages - thanks very much
  • femalefaust,
    impressive.

    thanking you in advance for including this utility in a page i am cobbling together, with attribution, of course.

    ping me if you want no part of it.

    i will post the link here when done.

    "o that this reader's comprehension exceedeth her skill, else, what is ^c for?"
  • tvp,
    I am using power shell script but not getting the same encoded string. Can you let me know what I am doing different?

    $file1 = "${@Trigger.AttachmentPath}\%{ForEachValue.Value}"
    $content1 = Get-Content $file1 -Raw
    $bytes = [System.Text.Encoding]::UTF8.GetBytes($content1)
    $base64 = [System.Convert]::ToBase64String($bytes)
    return $base64;
  • Chris,
    Thanks for the excellent, simple tool! I use it regularly.
  • inaldo,
    Thank you, helped a lot. cheers
  • luis,
    Thanks for the page!
  • Josh,
    Hello there, I am curious whether you save the content we upload to the server. Could you please enlighten me on this?
    • Administrator,
      Hello! No, the uploaded content is not stored anywhere.
  • username666,
    I found on my game this
    VGhlIHN0b25lIG9mIGxpdmUNCklmIHlvdSBkaWQgdGhlIHN0b25lIG9mIGxpdmUgeW91IGRpZCBhIGluZmluaXR5IGxpdmU=
    what the hell is that
    • fartaa,
      The stone of live
      If you did the stone of live you did a infinity live
  • Slotshop,
    We are Slotshop
    Mini Bingo : A minhoca do morango
  • pgn,
    (1)N3q8ryccAATFpSLgsIgBAAAAAAA4AAAAAAAAAP/FeeQO/KJfQ6deGE2exP2F913XPT3F78n2vYGiVwCEC4z3HJpinYpjMlBPOmrKs/TNColr7L0Q83/vV9GhCsEpcIw3OQ+e9SzWWXUm31e61nrwbrHRPRG6dI5u95+k0P4NCN3xNQzg8F/3ZRLM0UCKuCgu+ohG0eWUav49gvW/7YegDvX40nyVeWa5jcYuPVr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Yr7L9NqsB2J8dHFHnZjNImVftxESZsylSbV8+iqfYjw2YCaEt417fZ7/XzpfFpJd+KHBEdBEkiPavedP1nNwlw6+KUdcxpf6KYBhzvcQyZcLoOnCVvclpBlqnRjKMMo3icrFYnXWdl/NnS4AO9c8+QT7PWgtcDc7H/4vSSiL8R1MS09RvIJEx08mHvCoSUsWpomBvB5vI/jN2dj61V2O4wDxJK3bLU2DKAkYvwq2qA2v8JAOpb3zvsib5+IbCr0hN++YxL9qtJ7d4oY5WbH6fj0joUt3M4N8zh7kGIgN5TE80IbPhP3OGM20wf78QNWU4CFc0EPVIvJFmA0pYDagbqK94ZKDOnKQ8Uz6Yzy8RRmT2MbK0tD4p5qGvPS3zE8iontJTMfGmNSfDF4ItYgB3lxmzKducXoSZAjdZAfDJiaKIf3qMUGJPke/diuFUe7Qj/E4rmXN6B9ytFujFLM1dwH9u/iSzRHc5hI+WTQNUUcAAIs2lGl2G14HyPHfWeyEhAmUbHSk5ZEC37cIbJ9B+wdXN76pQB4kaWqTleMWHWJ2YLg9qW3i+g+zfdEWMPBEYnNQPVPxoNO3+ubbsLe9G8QdKdkLrMEGuGImQxqzUo8odG+HO166s1KSL1mUxpmN50tXVOqSafh6HuL0lFyRuGtDI5E4JreD9FENR9JA6o/8YJS608ckWKea5N9D0RkKtdg/
  • yossimazaltov,
    why base64 string from C# is different from base64 in Delphi?

    in c#
    byte[] byteArray = System.IO.File.ReadAllBytes(@FullFileName);
    string temp_inBase64 = Convert.ToBase64String(byteArray);

    in Delphi
    function ConvertPdfFileToBase64D(PdfFileName : String; var Base64Str : String) : Boolean;
    var
    success : Boolean;
    b64 : String;
    fBytes : TBytes;
    fSize : Integer;

    function FileToBytes(const AFileName: string; var Bytes: TBytes): Boolean;
    var
    Stream: TFileStream;
    begin
    if not FileExists(AFileName) then
    begin
    Result := False;
    Exit;
    end;
    Stream := TFileStream.Create(AFileName, fmOpenRead);
    try
    fSize := Stream.Size;
    SetLength(Bytes, fSize);
    Stream.ReadBuffer(Pointer(Bytes)^, fSize);
    finally
    Stream.Free;
    end;
    Result := True;
    end;
    begin
    Result := False;
    Base64Str := '';
    if FileToBytes(PdfFileName,fBytes) then
    begin
    //Base64Str := TNetEncoding.Base64.EncodeBytesToString(fBytes, fSize);
    Base64Str := TNetEncoding.Base64.EncodeBytesToString(fBytes);
    Result := True;
    End;
    end;
  • tomy,
    Hello! Yes, the uploaded content is yes stored anywhere.
  • saper_2,
    Hi,

    Can you add to input/output format a base64 with line length capped at 76char (and maybe with header/footer lines like "-----BEGIN BASE64-----"/"-----END BASE64-----" )
  • nqhXncMU,
    CCqcQAoT' OR 675=(SELECT 675 FROM PG_SLEEP(15))--
  • nqhXncMU,
    (select(0)from(select(sleep(15)))v)/*'+(select(0)from(select(sleep(15)))v)+'"+(select(0)from(select(sleep(15)))v)+"*/
  • nqhXncMU,
    if(now()=sysdate(),sleep(15),0)
  • shikher,
    hi accidently uploaded some confidential file to convert , just wanted to know uploaded files are stored somewhere or are deleted after conversion?
  • crackLore,
    Hey dog, 64 is totally ????? ?
  • Omar,
    Is base 64 and multipart data are same?
  • NotFenixio,
    This is awesome. Just what I needed, instantly. Thanks for making such amazing tools.
Add new comment

If you have any questions, remarks, need help, or just like this page, please feel free to let me know by leaving a comment using the form bellow.
I will be happy to read every comment and, if necessary, I will do my best to respond as quickly as possible. Of course, spammers are welcome only as readers.