Skip to content

Instantly share code, notes, and snippets.

@OrkoHunter
Created September 1, 2017 15:44
Show Gist options
  • Save OrkoHunter/0a3cd65f7f5d8fa4c7a944c02b94b51f to your computer and use it in GitHub Desktop.
Save OrkoHunter/0a3cd65f7f5d8fa4c7a944c02b94b51f to your computer and use it in GitHub Desktop.
http.server with upload
import os
from flask import Flask, request, redirect, url_for
from werkzeug import secure_filename
UPLOAD_FOLDER = '.'
app = Flask(__name__)
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
@app.route("/", methods=['GET', 'POST'])
def index():
if request.method == 'POST':
file = request.files['file']
if file:
filename = secure_filename(file.filename)
file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
return redirect(url_for('index'))
return """
<!doctype html>
<title>Upload new File</title>
<h1>Upload new File</h1>
<form action="" method=post enctype=multipart/form-data>
<p><input type=file name=file>
<input type=submit value=Upload>
</form>
<p>%s</p>
""" % "<br>".join(os.listdir(app.config['UPLOAD_FOLDER'],))
if __name__ == "__main__":
app.run(host='0.0.0.0', port=5001, debug=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment