0

I'm having a little problem! I'm designing an asp mvc 4 application for a client which should import and process an excel file. To process the excel file I use the C# version of the NPOI framework.

My client uses mac and I use windows.

Everything works fine on windows but when my client tries it on his mac, it does not work anymore. After doing some searching I found that the content type of the uploaded file was "application/octet-stream" when uploading from mac (opposed to "application/vnd.ms-excel" when uploading from windows).

We use the exact same file, the only difference is that my clients file is saved on a mac and mine on a windows pc (we both got the same file from google docs).

It became weirder when he was experiencing the same error when he tried it on a windows pc with the file which was saved on mac.

Does anybody have an idea on what is going on? Or how I can get my NPOI processing working when the content type is "application/octet-stream"?

1 Answers1

0

The browser can freely choose what content type to send. It could even send you "fluffy/bytes" if it wanted and you can't do anything about it. It appears that Safari on Mac does not know what an Excel file is so it does not send the Excel content type.

What is NPOI? Why does your application require that content type to be set? You can recognize that this is an Excel file by looking at the file extension that was posted. If neither content type not extension were posted (entirely possible) you can only guess by the file contents.

usr
  • 168,620
  • 35
  • 240
  • 369
  • NPOI is the framework I use to read the excel file. NPOI needs a file with content type "application/vnd.ms-excel". My application doesn't really require it. – Wouter Janssens Feb 27 '13 at 18:51
  • Can I somehow force force my application to recognize that the file is an excel file? Something like programmatically changing the content type. – Wouter Janssens Feb 27 '13 at 18:54
  • What data do you give to the framework? How do you call it? Can't you just hand it a byte[]? – usr Feb 27 '13 at 23:13
  • I hand over the inputstream of the uploaded file. HttpPostedFileBase selectedFile = (retrieve from request); HSSFWorkbook workbook = new HSSFWorkbook(selectedFile.InputStream); This is how I do it. It does not accept a byte array! – Wouter Janssens Feb 28 '13 at 07:50
  • If it only has a stream, where does it get the content type info from? It can't possibly know the content type so it can't possibly decide on it. Your bug is elsewhere. I suggest you accept this answer and ask a new question where you post code and the error message you are receiving. That wouldn't fit into this question. – usr Feb 28 '13 at 12:18