gpt4 book ai didi

file-upload - flask 中的文件上传错误

转载 作者:行者123 更新时间:2023-12-04 13:22:45 24 4
gpt4 key购买 nike

@app.route('/registerdriver', methods=['POST'])
def register_driver():
fname = request.form['fname']
lname = request.form['lname']
email = request.form['email']
mobno = request.form['mobno']
password = request.form['password']

file = request.files['driving_license']
file.filename = mobno+"_"+fname

filename = secure_filename(file.filename)
file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))

上面是我用来保存文件的代码。但是在尝试保存文件时会弹出以下错误

flask.debughelpers.DebugFilesKeyError

flask.debughelpers.DebugFilesKeyError: You tried to access the file "driving_license" in the request.files dictionary but it does not exist. The mimetype for the request is "application/x-www-form-urlencoded" instead of "multipart/form-data" which means that no file contents were transmitted. To fix this error you should provide enctype="multipart/form-data" in your form.



浏览器改为传输一些文件名。

有人可以帮我弄这个吗

最佳答案

在您的 html 表单标签中包含

<form action="/path" method="post" enctype="multipart/form-data">
</form>

关于file-upload - flask 中的文件上传错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47679398/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com