ファイルをBase64に変換する方法(無料)
- 選ぶ
- 見る
- コピーする
画像やPDFを、メールの本文やプログラムのコードの中に、文字として入れたい。ファイルとBase64を相互変換する は、ファイルをBase64という文字列に変換し、また元のファイルに戻すツールです。ファイルや文字は、この端末の中で変換します。どこにも送られません。
手順(ファイル → Base64)
- 「向きを選ぶ」で、「ファイル → Base64」を選びます。
- 「ファイルを1つ選ぶ」で、変換するファイルを選びます。
- 画像などを、HTMLに埋め込みたい場合は、「データURLの形式にする(data:…;base64,)」にチェックを入れます。
- 変換されると、「変換後のBase64」に文字列が出ます。
- 「結果をコピー」でコピーして使います。
手順(Base64 → ファイル)
- 「向きを選ぶ」で、「Base64 → ファイル」を選びます。
- 「Base64の文字」に、文字列を貼り付けます。
- 「保存するファイル名」を入れます(拡張子つき。例:image.png)。
- 「ファイルとして保存」で保存します。
Base64とは
バイナリのデータ(画像やPDFなど)を、英数字と少しの記号だけで表した文字列のことです。文字しか扱えない場所に、ファイルのデータを入れたいときに使われます。
向いている場面
- 小さな画像を、HTMLやCSSに直接埋め込む
- APIに、ファイルを文字として送る
- 設定ファイルに、小さなデータを入れる
- 受け取ったBase64を、ファイルに戻す
例
小さなアイコン画像を、HTMLに直接埋め込みたかった。「データURLの形式にする」にチェックを入れて変換し、結果をHTMLのsrcに貼り付けた。
つまずきやすい点
- 結果が長い:Base64にすると、文字数が元のデータの約1.3倍になる。
- 「Base64として読み取れませんでした。」と出る:文字が欠けている、余分な文字がある。
- ファイルが開けない:保存するファイル名の拡張子が、元の形式と違う。
よくある質問
暗号化されますか?
いいえ。Base64は、暗号化ではありません。誰でも元に戻せます。秘密の情報の保護には、使えません。
ファイルは、どこかに送られますか?
いいえ。ブラウザの中で変換します。
まとめ
向きを選び、ファイルか文字を入れて、結果を使う。Base64は暗号ではない点に注意しましょう。
ファイルとBase64を相互変換するを使う(無料)あわせて使えるツール
- ファイルのハッシュ値を調べる(SHA-256):ファイルのハッシュ値を調べて、照合します。
- CSVとJSONを相互変換する:CSVとJSONを、すぐに相互変換します。
- ファイルをZIPにまとめる:複数のファイルを、1つのZIPにまとめます。
同じツールの、ほかの解説
How to Convert a File to Base64 (Free)
- Choose
- Look
- Copy
You want to put an image or PDF into an email body or program code as text. Convert Files and Base64 converts a file to a Base64 string, and converts it back to the original file. Files and text are converted inside this device and sent nowhere.
Steps (file → Base64)
- For "Direction", choose "File → Base64".
- With "Choose one file", choose the file to convert.
- To embed an image in HTML and the like, tick "Use data URL format (data:…;base64,)".
- After conversion, the string appears under "Base64 after conversion".
- Copy it with "Copy result" and use it.
Steps (Base64 → file)
- For "Direction", choose "Base64 → file".
- Paste the string into "Base64 text".
- Enter a "File name to save" (with extension, for example image.png).
- Save with "Save as file".
What Base64 is
A string that expresses binary data (images, PDFs and so on) using only letters, digits and a few symbols. It is used when you want to put file data somewhere that can only handle text.
Good for
- Embedding small images directly in HTML or CSS
- Sending a file as text to an API
- Putting small data in a configuration file
- Turning received Base64 back into a file
Example
Wanted to embed a small icon image directly in HTML. Ticked "Use data URL format", converted, and pasted the result into the HTML src.
Common stumbling blocks
- The result is long: Base64 makes the character count about 1.3 times the original data.
- "Could not read as Base64." appears: characters are missing or extra characters are included.
- The file won't open: the extension of the file name to save differs from the original format.
Frequently asked questions
Is it encrypted?
No. Base64 is not encryption. Anyone can restore it. It cannot be used to protect secret information.
Are files sent anywhere?
No. They are converted inside the browser.
Summary
Choose the direction, enter a file or text and use the result. Note that Base64 is not a cipher.
Use "Convert Files and Base64" (free)Tools that go well with this
- Check a File's Hash (SHA-256): Calculate a file's hash and compare it.
- Convert CSV and JSON: Convert between CSV and JSON instantly.
- Make a ZIP File: Pack several files into one ZIP.