application/octet-stream WTF?

December 17th, 2008

Lately I’ve been having this problem with uploaded files using the Paperclip plugin (though I don’t think it has anything to do with the plugin).

My customers are trying to upload CSV files to their Donor Tools account. Normally, when you upload a .csv file, the content type is set to “text/csv” or some variation of “text/*”.

Here’s the problem: when uploading .csv files in Windows using any version of IE or Firefox, the content type is set to “application/octet-stream”.

What the flip?

This only occurs with IE or Firefox. Safari for Windows uploads the exact same file with the content type set correctly to “text/csv”.

To get around the problem I’ve temporarily turned off the file type validation, which I don’t like because I really don’t want to be accepting uploaded binary files.

Has anyone seen this problem before? How did you deal with it?


Have a big migration that would take too long to complete? It would be too bad to inadvertently bring down your whole server by loading a big dataset into memory.

A very simple solution is to use will_paginate. I was just combing through the plugin code, and found out that will_paginate has a nice method called paginated_each, which “Iterates through all records by loading one page at a time. This is useful for migrations or any other use case where you don’t want to load all the records in memory at once.”

So instead of writing for article in Article.find(all), you’re better off using Article.paginated_each do |article|. Your migrations will finish faster and with less memory usage.