烧瓶无法读取从html上传的图像

时间:2020-07-02 12:25:34

标签: python html flask

我正在尝试制作一个简单的html网页,用户可以在其中上传图片。该图像通过一种形式传递到烧瓶API,其中该图像传递到图像分类模型。但是,上传文件后,我无法在Flask API中接收该图像。我说错了 werkzeug.exceptions.BadRequestKeyError: 400 Bad Request: The browser (or proxy) sent a request that this server could not understand. KeyError: 'uploaded_img' 谁能指导我哪里出问题了?

我的html代码:

<body class="center-screen">
    <div id="content">
        <form id="url-form" action="/classify_image" method="post" enctype="multipart/form-data">
            <h1>Upload Image</h1>
            <div class="formcontainer">
                <hr/>
                <div class="container">
                    <label for="img">Upload image:</label>
                    <input type="file" id="img" name="uploaded_img" accept="image/*">
                </div>
                <button type="submit">
                    <strong>Classify Image</strong>
                </button>
            </div>
        </form>
    </div>
</body>

我的烧瓶端点:

@app.route('/classify_image', methods=['POST'])
def classify_image():
    if request.method == 'POST':
        print("Running")
        f = request.files['uploaded_img']
        model.predict(f)

0 个答案:

没有答案