I'm trying to get the current browser's MIME type for a file extension using JavaScript. The problem is, that I don't have a File-object coming from an input or drop operation.
I tried this without success:
var f = new File([''], 'test.xml');
console.log(f.type); // outputs "" but I expect anything like "application/xml"
Background why I am asking this is that I have a whitelist of allowed extensions to upload. While dragging a file over a drop zone, I would like to indicate whether the files are ok to drop or not. While dragging, I get the MIME types of the files but not the file names. My idea is to generate a local array of MIME types based on the allowed file extensions for comparism. I don't want to maintain a list of mime types on my backend because MIME types does not seem to be concise and relyable across browsers / OS'es.
Update: See comment why this question is not a duplicate.