Created
February 13, 2019 12:42
-
-
Save akmamun/9ab677536f79b62e7052620b854cb37f to your computer and use it in GitHub Desktop.
Base 64 to Image Convert in Python
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
import os | |
SAVE_DIR = os.path.dirname(os.path.abspath(__file__)) | |
def base64_to_image(filename): | |
path = os.path.join(SAVE_DIR, 'images/') | |
if not os.path.isdir(path): | |
os.mkdir(path) | |
data = base64.b64decode(filename) | |
filename = 'frame' + str(datetime.datetime.now().microsecond) + '.jpg' | |
destination = "/".join([path, filename]) | |
with open(destination, 'wb') as f: | |
f.write(data) | |
return data | |
# @app.route('/frame/upload/', methods=['GET', 'POST']) | |
# def upload_image(): | |
# if request.method == "POST": | |
# file = request.form['images'] | |
# convert_to_image(file) | |
# return "Successfully", 201 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment