So, I am using the following mechanism to try and upload a file to the backend using flask. In my template, I have the following:
<form action="{{ url_for('upload') }}" method="post" id="upload-form">
<input type="file" name="uploaded_document" onchange="changeListener(event)" id="embedfileinput" accept="image/jpeg, image/tiff, image/png, application/pdf" style="display:none"/>
<button class="ui left floated positive submit button" id="upload-button" type="submit" onclick="clickListener(event)">Upload Document</button>
</form>
So when I click on the upload-button
button, the following javascript gets executed:
function clickListener(e) {
document.getElementById('embedfileinput').click();
e.preventDefault();
}
This allows me to select a file and then the following javascript gets executed:
function changeListener(e) {
document.forms["upload-form"].submit()
}
However, on the flask side, I have the following:
@app.route("/upload", methods=["POST"])
def upload():
if request.method == "POST":
print(request.files)
and this dictionary is always empty. So, somehow the file never gets uploaded.