3
votes
@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

1
Can you show me your html form? - Raja Simon
Simply include enctype="multipart/form-data" in your <form> tag. - Matt Healy
Being a beginner i forgot that :P - AlgorithimicDUMB

1 Answers

4
votes

In your html form tag include

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