Created
January 14, 2014 12:52
-
-
Save tolbkni/b6032c3ed78e5f4bb180 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
import os | |
from flask import Flask | |
from flask import request, url_for, redirect | |
from werkzeug.utils import secure_filename | |
UPLOAD_DIR = "/tmp/uploads" | |
app = Flask(__name__) | |
app.config["UPLOAD_FOLDER"] = UPLOAD_DIR | |
@app.route("/") | |
def hello_world(): | |
return "Hello World" | |
@app.route("/upload", methods=["GET", "POST"]) | |
def upload_file(): | |
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('uploaded_file', file=file)) | |
return ''' | |
<!DOCTYPE html> | |
<title>Upload new File</title> | |
<h1>Upload new File</h1> | |
<form method="POST" enctype="multipart/form-data"> | |
<input type="file" name="file"> | |
<input type="submit" value="Upload"> | |
</form> | |
''' | |
@app.route("/upload/<file>") | |
def uploaded_file(file): | |
return "length={0:d}, file={1:s}".format(file.content_length, file) | |
if __name__ == "__main__": | |
app.run(port=10080, debug=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment