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:
<form action="" method=post enctype="multipart/form-data" id="testid"> <table> <tr> <td> <label>Upload</label> </td> <td> <input id="upload_content_id" type="file" name="upload_file" multiple> <input type="button" name="btn_uplpad" id="btn_upload_id" class="btn-upload" value="Upload"/> </td> </tr> </table> </form> 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
<input id="upload_content_id" type="file" name="upload_file" multiple> 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