Skip to content

Instantly share code, notes, and snippets.

@ichux
Created November 6, 2018 11:26
Show Gist options
  • Save ichux/26c506c33c1cd0fcef3aa9b8b1ac77fb to your computer and use it in GitHub Desktop.
Save ichux/26c506c33c1cd0fcef3aa9b8b1ac77fb to your computer and use it in GitHub Desktop.
The file that receives the upload
from flask import Flask, render_template, request, redirect, url_for
from werkzeug import secure_filename
app = Flask(__name__)
@app.route('/')
def index():
return render_template('index.html')
@app.route('/uploads', methods=['GET', 'POST'])
def uploads():
if request.method == 'POST':
up_file = request.files['file']
up_file.save(secure_filename(up_file.filename))
return 'file uploaded successfully'
else:
return redirect(url_for('index'))
if __name__ == '__main__':
app.run(debug=True, host="0.0.0.0")
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>File Uploader</title>
</head>
<body>
<form action="/uploads" method="POST"
enctype="multipart/form-data">
<input type="file" name="file"/>
<input type="submit"/>
</form>
</body>
</html>
POST /uploads HTTP/1.1
Host: 127.0.0.1:5000
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:62.0) Gecko/20100101 Firefox/62.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Referer: http://127.0.0.1:5000/
Content-Type: multipart/form-data; boundary=---------------------------4062220045227074151935407675
Content-Length: 277
DNT: 1
Connection: keep-alive
Upgrade-Insecure-Requests: 1
-----------------------------4062220045227074151935407675
Content-Disposition: form-data; name="file"; filename="biker.txt"
Content-Type: text/plain
This is some text!
Uploaded through the web by using telnet.
-----------------------------4062220045227074151935407675--
nc -vv localhost 5000
telnet localhost 5000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment