Base64として読み取れないとき
- 確かめる
- 直す
「Base64として読み取れませんでした。文字を確かめてください。」と表示されて、ファイルに戻せない。ファイルとBase64を相互変換する の「Base64 → ファイル」で、エラーが出るときの原因と直し方をまとめます。
まず確認すること
- 文字が途中で切れていないか:最初から最後まで、全部をコピーしたか。
- 余分な文字が混ざっていないか:前後に、説明文や引用符、スペースが入っていないか。
- 向きは合っているか:「Base64 → ファイル」を選んでいるか。
手順(直す)
- 文字の途中で切れていないか、確かめます。
- 余分な文字が混ざっていないか、確かめます。
- もう一度、「Base64の文字」に貼り付けます。
- 「保存するファイル名」を入れて、「ファイルとして保存」を押します。
よくある原因
- コピーの不完全:長い文字列の一部しか、コピーされていない。
- 引用符が付いている:文字列の前後に、「"」が付いたまま。
- 「data:…;base64,」の部分:データURLの先頭が、付いたままで問題が出る場合がある。取り除いて、再度試す。
- 改行・スペース:途中に入っている。取り除く。
- 全角の文字が混ざっている:全角の英数字は、使えない。
- URL用のBase64:「+」「/」の代わりに「-」「_」を使う方式がある。
- 文字数が合わない:4の倍数に満たない。末尾の「=」が欠けている。
余分な部分の取り除き方
- 前後の、引用符や説明文を消す
- 「data:image/png;base64,」のような先頭の部分を消し、カンマの後の文字だけにする
- 改行を、テキストエディタで削除する
保存したファイルが開けない
Base64は読み取れたのに、ファイルが開けない場合は、拡張子が違う可能性があります。ファイルの種類に合った、ファイル名(拡張子)で保存し直します。
向いている対処
短い文字列で、試してみる。最初の数行だけ貼り付けて、読み取れるか確かめると、問題の場所が分かります。
例
APIの結果を貼り付けたら、エラーになった。前後に引用符が付いていたため、取り除いて貼り付けたところ、変換できた。
つまずきやすい点
- 途中から文字が欠ける:ブラウザやアプリの表示上限で、切れている。
- ファイルは作れたが、壊れている:データが一部欠けている。
よくある質問
どの文字が悪いのか、教えてくれますか?
このツールは、エラーの場所を表示しません。上のポイントを、順に確認してください。
まとめ
全部コピーしたか、余分な文字がないかを確認。先頭のデータURLの部分や、引用符を取り除いてみましょう。
ファイルとBase64を相互変換するを使う(無料)あわせて使えるツール
- ファイルのハッシュ値を調べる(SHA-256):ファイルのハッシュ値を調べて、照合します。
- CSVとJSONを相互変換する:CSVとJSONを、すぐに相互変換します。
- ファイルをZIPにまとめる:複数のファイルを、1つのZIPにまとめます。
同じツールの、ほかの解説
When the Base64 Cannot Be Read
- Check
- Fix
"Could not read as Base64. Check the characters." is shown and you cannot restore the file. Here are causes and fixes for errors in "Base64 → file" of Convert Files and Base64.
What to check first
- Is the text cut off?: Did you copy everything from start to end?
- Are extra characters mixed in?: Are there explanatory text, quotes or spaces before or after?
- Is the direction right?: Have you chosen "Base64 → file"?
Steps (fixing)
- Check that the text isn't cut off.
- Check that no extra characters are mixed in.
- Paste it into "Base64 text" again.
- Enter a "File name to save" and press "Save as file".
Common causes
- Incomplete copy: only part of a long string was copied.
- Quotes attached: quotes remain before and after the string.
- The "data:…;base64," part: the data URL prefix may cause problems if left on. Remove it and try again.
- Line breaks and spaces: inserted partway. Remove them.
- Full-width characters mixed in: full-width letters and digits can't be used.
- URL-safe Base64: there is a form using "-" and "_" instead of "+" and "/".
- Length doesn't fit: not a multiple of 4. The trailing "=" is missing.
Removing the extra parts
- Delete the quotes or explanatory text before and after
- Delete a leading part like "data:image/png;base64," and keep only the characters after the comma
- Delete line breaks in a text editor
When the saved file won't open
If the Base64 was read but the file won't open, the extension may be wrong. Save again with a file name (extension) that fits the file type.
A useful approach
Try with a short string. Pasting just the first few lines and seeing whether it reads shows where the problem lies.
Example
Pasting an API result gave an error. Quotes were attached before and after; after removing them and pasting, it converted.
Common stumbling blocks
- Characters go missing partway: cut by the display limit of the browser or app.
- A file was made but is corrupted: part of the data is missing.
Frequently asked questions
Does it tell me which character is bad?
This tool doesn't show the error location. Check the points above in order.
Summary
Check that you copied everything and that there are no extra characters. Try removing the leading data URL part and quotes.
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.