5
@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))

Above is the code I used for saving the file. However the following error pops out while trying to save the file

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.

The browser instead transmitted some file names.

Can someone help me with this

3
  • 1
    Can you show me your html form? Commented Dec 6, 2017 at 17:49
  • 6
    Simply include enctype="multipart/form-data" in your <form> tag. Commented Dec 6, 2017 at 23:51
  • Being a beginner i forgot that :P Commented Dec 8, 2017 at 13:09

2 Answers 2

10

In your html form tag include

<form action="/path" method="post" enctype="multipart/form-data">
</form>
Sign up to request clarification or add additional context in comments.

1 Comment

even after providing enctype="multipart/form-data" I get the same error
0
file = request.files.get('driving_license')

Try this because i had the same error even when i already have <form action="/path" method="post" enctype="multipart/form-data"> so now it should works with that

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.