Hi I'm quite new to flask and I want to upload a file using an ajax call to the server. As mentioned in the documentation, I added a file upload to the html as folows:
Upload |
and I wrote the ajax handler as this
$(document).ready(function() {
$("#btn_upload_id" ).click(function() {
$.ajax({
type : "POST",
url : "/uploadajax",
cache: false,
async: false,
success : function (data) {},
error: function (XMLHttpRequest, textStatus, errorThrown) {}
});
});
});
I do not know how to get the uploaded file (not the name) from this
and save the file in folder. I'm not quite sure how to read the file from handler which i have written:
@app.route('/uploadajax', methods = ['POST'])
def upldfile():
if request.method == 'POST':
file_val = request.files['file']
I will be grateful if anyone can help. Thank you in advance