This is a piece of note for solve the problem of using html input tag upload a file through Google Chrome, and the browser cannot recognized the real file content type in Windows system.

The situation is, I have a list of allow upload file content type in backend, and there is a html input tag for user to upload file

<input type="file" id="myfile" name="myfile" multiple>

when I upload a .doc file, backend throw an Unsupported file type error. Through the network request I realized the broswer can’t recognized the real content type, it shows unknown file type in Network -> Request URL-> Header -> Form Data, looks like this

Content-Disposition: form-data; name="file"; filename="your-file-name.txt"
Content-Type: application/octet-stream

If the browser know the content type for .doc it will be

Content-Type: application/msword

This error cause by some setting from my computer, I test same code and same file with different laptop, it works. After a bit research, I found out the reason might be because of there is no real content type in my registry editor\HKEY_LOCAL_MACHINE\Software\Classes\.docx folder

missing MIME content type

To add a content type for my .doc folder, all I need to do is just simply right click on the folder’s empty palce, choose New -> String Value, and name it as Content Type

missing MIME content type

After Content Type file added, right click on the file and choose Modify, add real content type for doc into this Value data field, like this

missing MIME content type

missing MIME content type

Then, done!!

PS: file content type for .doc & .docx are different, please have a look on List of MIME types if you need.

Any feedback is welcome! :-)