forked from datademofun/heroku-basic-flask
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.py
More file actions
39 lines (33 loc) · 1 KB
/
app.py
File metadata and controls
39 lines (33 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
from flask import Flask
from flask import render_template, request
from datetime import datetime
import os
app = Flask(__name__)
app.config['UPLOAD_FOLDER'] = 'tmp/'
@app.route('/')
def homepage():
return """
<html>
<body>
<form action = "/uploader" method = "POST"
enctype = "multipart/form-data">
<input type = "file" name = "file" />
<input type = "submit"/>
</form>
</body>
</html>
"""
@app.route('/uploader', methods = ['GET', 'POST'])
def upload_file():
if request.method == 'POST':
mypath = os.getcwd()+'/tmp/'
if not os.path.isdir(mypath):
os.mkdir(mypath)
f = request.files['file']
f.save(os.path.join(app.config['UPLOAD_FOLDER'],f.filename))
if os.path.exists(os.path.join(app.config['UPLOAD_FOLDER'], f.filename)):
return 'file uploaded successfully'
else:
return 'file upload fail'
if __name__ == '__main__':
app.run(debug=True, use_reloader=True)