forked from orbit-oss/flask
Doc for add check upload file
This commit is contained in:
parent
da1c1f0d7f
commit
02b02543b3
1 changed files with 9 additions and 0 deletions
|
|
@ -56,7 +56,16 @@ the file and redirects the user to the URL for the uploaded file::
|
||||||
@app.route('/', methods=['GET', 'POST'])
|
@app.route('/', methods=['GET', 'POST'])
|
||||||
def upload_file():
|
def upload_file():
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
|
# check if the post request has the file part
|
||||||
|
if 'file' not in request.files:
|
||||||
|
flash('No file part')
|
||||||
|
return redirect(request.url)
|
||||||
file = request.files['file']
|
file = request.files['file']
|
||||||
|
# if user does not select file, browser also
|
||||||
|
# submit a empty part without filename
|
||||||
|
if file.filename == '':
|
||||||
|
flash('No selected file')
|
||||||
|
return redirect(request.url)
|
||||||
if file and allowed_file(file.filename):
|
if file and allowed_file(file.filename):
|
||||||
filename = secure_filename(file.filename)
|
filename = secure_filename(file.filename)
|
||||||
file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
|
file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue