Created
December 7, 2021 13:18
-
-
Save prettyirrelevant/2b7de74dc4402d948761d1b01b75a7fa to your computer and use it in GitHub Desktop.
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 save_image_from_b64(b64_image): | |
file_name = secrets.token_hex(6) | |
file_data = b64_image.split(",")[-1].encode() | |
file_type = b64_image.split(",")[0].split(";")[0].split("/")[-1] or "png" | |
with open("{}/{}.{}".format(app.config["UPLOAD_FOLDER"], file_name, file_type), "wb") as f: | |
f.write(base64.decodebytes(file_data)) | |
return "{}.{}".format(file_name, file_type) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment