Skip to content

Instantly share code, notes, and snippets.

@narendraprasath
Last active June 17, 2020 16:17
Show Gist options
  • Save narendraprasath/4f2b65f0f2b9e64e4ac0853f67668a41 to your computer and use it in GitHub Desktop.
Save narendraprasath/4f2b65f0f2b9e64e4ac0853f67668a41 to your computer and use it in GitHub Desktop.
flask image serving endpoint
from flask import Flask, request, send_from_directory, send_file
import os
from flask_cors import CORS, cross_origin
# set the project root directory as the static folder
app = Flask(__name__, static_url_path='')
CORS(app)
app.config["CORS_HEADERS"]= 'Content-Type'
## flask endpoint to serve image using filename
@app.route('/img/<file_name:file_name>')
@cross_origin(origin='*',headers=['Access-Control-Allow-Origin','Content-Type'])
## send image as response
def send_img(file_name):
return send_from_directory('static/img', file_name)
## run flask app
if __name__ == "__main__":
app.run(host="0.0.0.0", port=5020)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment