Skip to content

Instantly share code, notes, and snippets.

Created Feb 4, 2020
What would you like to do?
Upload Base_64 Image File with Python Flask via REST API
from flask.views import MethodView
from flask import jsonify, request, abort
import uuid
import os
from io import BytesIO
from PIL import Image
import base64
class UploadAPI(MethodView):
def __init__(self):
if not request.json:
def post(self):
image_data = request.json['data']
extension = request.json['extension']
image_data = bytes(image_data, encoding="ascii")
image_name = str(uuid.uuid4()) + extension
image =
image_directory = os.path.join(os.getcwd(), 'static', 'upload', 'image','')
file_path = image_directory + image_name
# save image to file system
response = {
"message": "Image Uploaded",
"body": {
"image_id": image_name,
return jsonify(response)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment