User uploads Excel sheet - filetype is application/octet-stream

Viewed 7547

I have a web application running, laravel backend, where users upload Excel spreadsheets which then get stored, base64 encoded in a database. Mostly this works fine and the file is stored, looking like:

data:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;base64,UEsDBBQABgAIAAAAIQBi7p1oXgEAAJAEAAA

However recently a user has had problems, her files get uploaded and stored as:

data:application/octet-stream;base64,UEsDBBQACAgIAGVKWk0AAAAAAAAAAAAAA

If I download her files, they appear as perfectly OK Excel sheets, and if I upload them again, even without opening them, they upload as XML spreadsheets.

Where do I start looking for the problem? At what stage does this encoding get determined? Is the the uploading OS, the uploading browser, or might Laravel be doing something behind the scenes? I am not a Laravel expert.

2 Answers

As @ourmandave pointed out, browsers do not have a 100% reliable way to determine a MIME type: MIME types from browsers

In this case, the user downloaded a Google Sheet from Google Drive on a Chromebook (as .xlsx) and then uploaded the xls to me. The file was fine (and could be interpreted as an .xlsx file) but the MIME type at the file start on different Chromebooks could be:

data:application/octet-stream;base64

or just

data:;octet-stream

Conclusion: don't place too much faith in the MIME type on file upload.

In my case, the problem was not related to the browser. We tried to upload a Microsoft Excel Worksheet (.xlsx) file from several machines running on Windows. Same browser versions of Chrome (Version 83.0.4103.106), Edge (Version 83.0.478.54) and Firefox (77.0.1 (64-bit)) were used.

The difference appeared between the machines that had MS Office installed and those that didn't.

On the machines with MS office all browsers accepted the file with:

Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet

Browsers on the machines without MS Office accepted the file with:

Content-Type: application/octet-stream
Related