Created
February 2, 2021 17:45
-
-
Save akmamun/6f1ab520ca0c51b664be5ad03d0cacd5 to your computer and use it in GitHub Desktop.
Base 64 Image Check
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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