@app.route('/form') def form(): return render_template('form.html') @app.route("/upload", methods=['GET', 'POST']) def upload(): if request.method == 'POST': f = request.form.get('file') full_filename = os.path.join(app.config['UPLOAD_FOLDER'], 'resume1') f.save(full_filename) return ("Uploaded Successfully")
form.html
<html> <body> <form action = "/upload" method = "post" enctype = "multipart/form-data"> <input type = "file" name = "file" /> <input type = "submit" value = "Submit" /> </form> </body> </html>
I am trying to upload a file using flask but it is throwing me this error Please help
You cannot get the uploaded file using this line f = request.form.get('file'). You need to replace that line with this.
f = request.form.get('file')
f = request.files.get("file")
1.4m articles
1.4m replys
5 comments
56.9k users