When uploading a file to a Flask server, I can access files from the flask request global by using raw HTML with the following code:
<form id="uploadForm" action='upload_file' role="form" method="post" enctype=multipart/form-data>
<input type="file" id="file" name="file">
<input type=submit value=Upload>
</form>
In Flask:
def post(self):
if 'file' in request.files:
....
However, when trying to achieve the same result with Axios, the flask request global is empty:
<form id="uploadForm" enctype="multipart/form-data" v-on:change="uploadFile">
<input type="file" id="file" name="file">
</form>
uploadFile: function (event) {
const file = event.target.files[0]
axios.post('upload_file', file, {
headers: {
'Content-Type': 'multipart/form-data'
}
})
}
If I remove the headers json from the axios.post method in the uploadFile function above, the form key of my flask request object contains a comma-separated list of string values since the file is a .csv. So how can I send a file object via axios?