Skip to content

Instantly share code, notes, and snippets.

@anudit
Created May 17, 2020 12:59
Show Gist options
  • Save anudit/cd786e5093bf3dd7d498f7d2b2f93d39 to your computer and use it in GitHub Desktop.
Save anudit/cd786e5093bf3dd7d498f7d2b2f93d39 to your computer and use it in GitHub Desktop.
Minimal python file upload
from flask import Flask, render_template, request
from werkzeug import secure_filename
app = Flask(__name__)
@app.route('/upload')
def upload_file():
return render_template('upload.html')
@app.route('/uploader', methods = ['GET', 'POST'])
def uploader():
if request.method == 'POST':
f = request.files['file']
f.save(secure_filename(f.filename))
return 'file uploaded successfully'
if __name__ == '__main__':
app.run(debug = True)
<html>
<body>
<form action = "https://localhost:5000/uploader" method = "POST"
enctype = "multipart/form-data">
<input type = "file" name = "file" />
<input type = "submit"/>
</form>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment