app.py 文件源码

python
阅读 16 收藏 0 点赞 0 评论 0

项目:logo-detect 作者: sunbinbin1991 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号