Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from flask import Flask
- from flask import copy_current_request_context
- from flask import request
- from flask import render_template
- import gevent
- from flask_socketio import SocketIO
- app = Flask(__name__, static_url_path='/static', static_folder='./static')
- app.secret_key = "asdf" # constants.SECRET_KEY
- socketio = SocketIO(app)
- @app.route("/",methods=["POST","GET"])
- def home():
- with app.app_context():
- @copy_current_request_context
- def upload_files():
- def upload_file(fileobj):
- print(fileobj.read())
- print("Started")
- selected_files = request.files.getlist('files[]')
- print(selected_files)
- for selected_file in selected_files:
- print("filename:", selected_file.filename)
- gevent.spawn(upload_file, selected_file)
- print("Finished")
- if request.method == "POST":
- upload_files()
- # gevent.spawn(upload_files) # raise ClientDisconnected()
- # werkzeug.exceptions.ClientDisconnected: 400 Bad Request: The browser (or proxy) sent a request that this server could not understand.
- return render_template('index.html')
- if __name__ == "__main__":
- socketio.run(app, debug=True)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement