My images are stored in a MongoDB, and I'd like to return them to the client, here is how the code is like:
@app.route("/images/<int:pid>.jpg")
def getImage(pid):
# get image binary from MongoDB, which is bson.Binary type
return image_binary
However, it seems that I can't return binary directly in Flask? My idea so far:
- Return the
base64
of the image binary. The problem is that IE<8 doesn't support this. - Create a temporary file then return it with
send_file
.
Are there better solutions?