def upload():
# remove exsiting files
exsiting_files = os.listdir(app.config['UPLOAD_FOLDER'])
for file in exsiting_files:
os.remove(os.path.join(app.config['UPLOAD_FOLDER'], file))
# Get the name of the uploaded files
uploaded_files = request.files.getlist("file[]")
filenames = []
for file in uploaded_files:
# Check if the file is one of the allowed types/extensions
if file and allowed_file(file.filename):
# Make the filename safe, remove unsupported chars
filename = secure_filename(file.filename)
# Move the file form the temporal folder to the upload
# folder we setup
file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
# Save the filename into a list, we'll use it later
filenames.append(filename)
# Redirect the user to the uploaded_file route, which
# will basicaly show on the browser the uploaded file
# Load an html page with a link to each uploaded file
results = identify_logos(app.config['UPLOAD_FOLDER'])
return render_template('upload.html', results=results, length=len(results))
# This route is expecting a parameter containing the name
# of a file. Then it will locate that file on the upload
# directory and show it on the browser, so if the user uploads
# an image, that image is going to be show after the upload
评论列表
文章目录