thoughtbot/paperclip — Issue #747: content_type is not consistently determined
Author: jjb
Created: 2012-02-18 08:05:15+00:00
State: open

There are two notions of content type in the system.

1. when a file is uploaded, content type is [taken straight from the browser to be used for the foo_content_type](https://github.com/thoughtbot/paperclip/blob/master/lib/paperclip/attachment.rb#L113).

2. [an elaborate and well-thought-out path where the best candidate is chosen from several possibilities](https://github.com/thoughtbot/paperclip/blob/master/lib/paperclip/upfile.rb#L9) -- this is only applied to `File`, for use in which instances I'm not sure.

I'm having a problem when uploaded epubs (which do not have a registered MIME type) are being added to the system as application/octet-stream. I solved the problem with this:

```ruby

## in host model
before_post_process :set_content_type

def set_content_type
self.my_attachment.instance_write(:content_type, MIME::Types.type_for(self.my_attachment_name).to_s)
end

## in an initializer
MIME::Types.add MIME::Type.from_hash('Content-Type' => 'application/epub+zip',
'Extensions' => ['epub'])

```

For my purposes this is a complete solution. This could possibly be made better in the general case by not accepting when a content type is application/octet stream from the user's browser and using the logic from either Upfile or my pre-proces hook to determine a better content type.

Thoughts?