I know that the docx's MIME type is
application/vnd.openxmlformats-officedocument.wordprocessingml.document
But whenever I pick an docx file using <input type="file">, the type is empty ?
<!DOCTYPE html>
<html>
<body>
<input type="file" id="myfile" name="myfile" multiple><br><br>
<button onclick="logFile(event)">CLick</button>
</body>
<script>
function logFile(e) {
var myFile = document.getElementById("myfile");
console.table(myFile.files[0])
}
</script>
</html>
This code will log a table with type = application/pdf when you pick an pdf, but when you pick a docx file type = ""
Because of the type is empty, when I send it to my server, the browser auto read the docx files as application/octet-stream, which is not what I want
MIME types are not really a browser/client thing. Especially Windows knows nothing about them and uses the file extension instead, and neither it nor browsers have have a list or mapping of file extensions to MIME types.
Additionally, even if the browser would send a MIME type, you NEVER can trust anything that a client sends to you. You will in any case need to look at the content of sent file and check if it actually is the file type you expect.