Uploading *.docx returns octet-stream instead of officedocument.wordprocessingml.docu
Application Type
Traditional Web

My project requires a file upload to database and to display the file directly in browser, using IFrames.

In order to do that, I set multiple IFrames for the corresponding data type (.pdf, .docx, .xlsx, .jpg, etc.). Using FileUpload.DataType, I detected files according to their MIME types.

Problem is it seems that .docx files always get determined as application/octet-stream instead of application/vnd.openxmlformats-officedocument.wordprocessingml.document. Funny .xlsx files are detected correctly.

Does anyone have a better solution for this?

Annotation 2022-04-04 161352.png

mvp_badge
MVP
Solution

Makes sense, thank you for clarifying. 

If you want to keep the current flow of the application, my suggestion would be to consider other factors of the file itself. application/octet-stream is a generic MIME type, so if you detect it (or any other unknown MIME types) after a file upload, you could fallback to the file extension to determine the file type.

mvp_badge
MVP

Hello Davey,

Relying on specific MIME types is risky, because as you've discovered they can be inconsistent. Why do you need to determine the natura of the data being displayed in the Iframe? Do you have multiple Iframe patterns depending on the file? Would it be possible to rely on user input on upload instead of attempting to classify the file automatically?

Yes, I'm planning to use multiple Iframe patterns for each format.


I would rather have my project classify the file type automatically. There's only an upload and submit button and should it be possible, my system would upload the file and select the data type. The file can be viewed and the file type would determine which Iframe pattern to use. PDFs and images can be viewed directly in the browser. I would have to research more on viewing .docx and .xlsx files in browser.

mvp_badge
MVP
Solution

Makes sense, thank you for clarifying. 

If you want to keep the current flow of the application, my suggestion would be to consider other factors of the file itself. application/octet-stream is a generic MIME type, so if you detect it (or any other unknown MIME types) after a file upload, you could fallback to the file extension to determine the file type.

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.