4

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.

Dan
  • 1,249
  • 2
  • 16
  • 31
  • 1
    What recently changed? Is she using a different browser, or changed Excel versions, or is saving the file with a different file format? Maybe it used to .xls and she changed it to .xlsx. – ourmandave Oct 27 '18 at 15:33
  • [Here's an answer for how browser's determine the mime-type of the file being uploaded.](https://stackoverflow.com/a/26303098/3585500) – ourmandave Oct 27 '18 at 15:39
  • I found out she was using a Chromebook and the spreadsheet was originally a Google Sheet. Must find a Chromebook to reproduce.. – Dan Oct 29 '18 at 16:08

2 Answers2

3

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.

Dan
  • 1,249
  • 2
  • 16
  • 31
3

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
Damir Varevac
  • 341
  • 2
  • 10