0

我正在尝试将视频从反应上传到烧瓶,但是当我发出 POST 请求时,它给了我这个错误

werkzeug.exceptions.BadRequestKeyError: 400 Bad Request: The browser (or proxy) sent a request that this server could not understand.
KeyError: 'file'

这是后端:

@app.route("/releaseVideo",methods=["POST"])

def release():

    request_data = request.files.get["file"]
    print(request_data)
    try:
        request_data.save(os.path.join(app.config['UPLOAD_FOLDER'],'first video'))
    except Exception:
        print('COULD NOT')
    return {"msg":"What am I DOING"},200


if __name__ == '__main__':
    app.run(debug=True)

这是前端......我使用 axios 而不是 fetch 因为我听说 axios 比 fetch 更适合文件上传。

    const upload_file = (event) => {
        event.preventDefault()
        let file = document.querySelector('input[type="file"]')
        const formdata = new FormData()


        formdata.append("file",file);
    axios("/releaseVideo", {
        method:'POST',
        body:formdata
    })
    .then(res => console.log(res))
    .catch(err => console.warn(err));

    }







    return (
        <>
            <form onSubmit={upload_file}>
                <label>Title: </label><br />
                <input type="text" onChange={onTitleChange} value={title}/><br />
                <label>Description:</label><br />
                <textarea value={textArea} onChange={onTextAreaChange}></textarea>
                <input type="file" id="file"/>
                <input type="submit" value="Upload Video!" />

            </form>
        </>
    )

那么如何以正确的方式从前端获取视频呢?

4

0 回答 0