By Relwick · Published
A system returns a long block of letters and numbers instead of a normal photo download. Renaming a text file containing that block may create a JPG filename without creating a usable JPEG.
The correction is to obtain the decoded image, not to repeatedly rename or compress the text file.
Quick answer & key takeaways
Base64 is a text representation of bytes. Saving that text as photo.jpg does not decode it into a JPEG file. A data URL can also include a media-type prefix that is not part of the image bytes. Prefer the source app’s image download or export. If decoding is necessary, use the complete, correctly identified encoding and verify the resulting image before preparing it for upload.
- An encoded representation is different from the image bytes.
- A data URL includes syntax beyond its payload.
- Verify the decoded file before using image preparation tools.
Recognise the representation
MDN documents data URLs as a scheme with an optional media type, an optional Base64 marker, and a payload separated by a comma. A value beginning with data:image/jpeg;base64, therefore contains both a description and encoded content. That entire line is not a JPEG file header.
Other exports may contain a Base64 value inside JSON without a data-URL prefix. Some values use another encoding entirely. Use the source system’s documented export format instead of assuming that any long text string represents a photograph.
Separate the filename from the content
| What you have | What it means |
|---|---|
| A normal downloaded JPEG | The file contains image-format bytes. |
| Base64 text in a text file | The file contains an encoded representation. |
| A complete image data URL | A prefix identifies how to interpret its payload. |
| A JSON export with an image field | The image representation is part of a larger record. |
Changing .txt to .jpg alters the name, not the stored bytes. An image application can reject the renamed file even when its icon now resembles an image. Repeated extension changes cannot repair missing or truncated encoded content.
Recover the image through the source
Return to the application that produced the value and look for its actual image download or export. This is usually easier to verify than copying a long text field from a preview, where the displayed value may be shortened or escaped.
If you control the integration, follow its documented decoding procedure on the complete payload. Keep the data-URL prefix separate from Base64 decoding, and distinguish standard Base64 from other variants. Decode errors should lead back to the source value rather than to guessed missing characters.
Base64 does not make the photo confidential. Treat encoded personal images with the same care as the original file. Avoid pasting them into an unfamiliar service merely because they look like technical text instead of a recognisable face or document.
Verify before preparing the upload
Open the recovered image and confirm that it shows the expected content. Use File checker to inspect a supported file’s actual type, size, and dimensions. Its file selector is not a Base64 text-decoding interface.
Once you have a real image file, apply the destination’s required dimensions or size limits with the appropriate image tool. Check the decoded file’s byte count; the length of an encoded text value is not the same measurement as the image file size.
Frequently asked questions
Will renaming Base64 text to PNG decode it?
No. A filename change does not perform binary decoding or image conversion.
Is every data URL Base64?
No. The syntax can describe other payload encodings. Read the prefix and source documentation.
Does Base64 hide a private image?
No. It is an encoding, not a confidentiality mechanism.
Sources and further reading
- MDN: data URLs — Explains the media type, optional Base64 marker, separator, and payload in a data URL.
Summary
Obtain the actual image bytes first. Format checks, resizing, and compression become meaningful only after the encoded representation has been correctly recovered.