Skip to content

Instantly share code, notes, and snippets.

@subnetmarco
Created September 10, 2012 20:08
Show Gist options
  • Select an option

  • Save subnetmarco/3693500 to your computer and use it in GitHub Desktop.

Select an option

Save subnetmarco/3693500 to your computer and use it in GitHub Desktop.
Flask Upload Sample
import os
from flask import Flask, request, redirect, url_for
from werkzeug import secure_filename
UPLOAD_FOLDER = '/tmp'
app = Flask(__name__)
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
@app.route("/upload", methods=['POST'])
def upload():
   file = request.files['file']
   if file:
       filename = secure_filename(file.filename)
       path = os.path.join(app.config['UPLOAD_FOLDER'], filename)
       file.save(path)
       return str(os.path.getsize(path)) + " bytes\n"
   return "error"
if __name__ == "__main__":
   app.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment