Skip to content

Instantly share code, notes, and snippets.

@di
Created October 31, 2016 17:59
Show Gist options
  • Save di/35c7f08f27af97bbe997f2f288e9e216 to your computer and use it in GitHub Desktop.
Save di/35c7f08f27af97bbe997f2f288e9e216 to your computer and use it in GitHub Desktop.
simple flask server which receives files and stores them locally
import os
from flask import Flask, request
from werkzeug.utils import secure_filename
app = Flask(__name__)
app.config['UPLOAD_FOLDER'] = '.'
@app.route('/', methods=['POST'])
def upload_file():
file = request.files['filedata']
if file:
filename = secure_filename(file.filename)
file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
return 'it worked'
return 'no file'
@app.route('/', methods=['GET'])
def index():
return 'it works'
if __name__ == '__main__':
app.run('0.0.0.0', port=80, debug=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment