Reputation: 167
I have an application where I allow users to upload supporting documents. I'm using the cffile tag to save the files.
The tag looks like this:
<cffile action="upload"
destination="path..."
nameconflict="makeunique"
ACCEPT="application/msword, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/pdf, application/vnd.openxmlformats-officedocument.presentationml.presentation, application/vnd.openxmlformats-officedocument.wordprocessingml.document, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
filefield="outline">
An .xls file was uploaded and an error was generated stating that the uploaded file "application/octet-stream" was not accepted.
The question is why was an .xls spreadsheet file interpreted by the server as having a "application/octet-stream" mime-type?
Upvotes: 2
Views: 3183
Reputation: 7193
Uh oh... I hate to disagree with Sun Flower but the issue here is extension mapping on the server not on the client. The file arrives on the server and ColdFusion "looks up" the mime type based on the extension. Having never installed Excel on your server it's quite possible there is no associated mime type on it. Remember that nothing that depends on the client is going to help you here. The file arrives, it has an extension and the extension must match something that the server knows about.
If this is windows you can add the mime types to IIS (just do a search for "mime types - IIS6 or IIS7 for instructions) and I believe that it will automatically add the associated mime type to the underlying registry hive. Otherwise it is a registry hack. I'm going from memory here and I'm too tired to look it up :)
Sorry - missed your question about application/octet-stream. That is the default mime type for an arbitrary file. Sort of a catch-all.
Upvotes: -1
Reputation: 32885
forget about the accept
attribute since CF (9 and below) only checks file extension even if the client browser sends the correct MIME type.
Just have the file uploaded, and then check the file extension against your white list.
Without accept
, you'll not even get that exception.
Upvotes: 0
Reputation: 29
I suspect that the client's browser had not been configured to pick the correct mime type for .xls files. Most likely, the mime type of application/octet-stream was sent in the HTTP headers, in the request.
Upvotes: 2