from flask import Flask, render_template, url_for, request, redirect
from pymongo import MongoClient
from PIL import Image
import io
from matplotlib import pyplot as plt
app = Flask(__name__)
client = MongoClient("localhost", 27017)
db = client.data
todos = db.images
@app.route("/", methods=["POST", "GET"])
def home():
if request.method == "POST":
imagedata = request.files["file"]
image_bytes = io.BytesIO()
imagedata.save(image_bytes, format="JPEG")
image = {
image: image_bytes.getvalue()
}
todos.insert_one(image)
return redirect(url_for("home"))
return render_template("index1.html")
if __name__ == "__main__":
I am trying to store image file in mongoDB using flask and pymongo but i don't understand what was the problem