Skip to content

Instantly share code, notes, and snippets.

@akmamun
Created February 2, 2021 17:45
Show Gist options
  • Save akmamun/6f1ab520ca0c51b664be5ad03d0cacd5 to your computer and use it in GitHub Desktop.
Save akmamun/6f1ab520ca0c51b664be5ad03d0cacd5 to your computer and use it in GitHub Desktop.
Base 64 Image Check
def is_base64(base_64):
try:
if len(base_64) == 0:
return False
if isinstance(base_64, str):
# If there's any unicode here, an exception will be thrown and the function will return false
sb_bytes = bytes(base_64, 'ascii')
elif isinstance(sb, bytes):
sb_bytes = base_64
else:
raise ValueError("Argument must be string or bytes")
return base64.b64encode(base64.b64decode(sb_bytes)) == sb_bytes
except Exception:
return False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment