Paper_clip s3 - application/octet-stream?
All my rails paper_clip images are being uploaded to Rails as "application/octet-stream"
Which is casuing issues.
How in Rails do I set the content/type to the right type? Image/png etc, based on the actual image being uploaded?
Thanks开发者_开发知识库
Well, in general you can always detect the proper mime-type from the uploaded file itself by using 'mime/types':
# Controller
def create
@photo = Photo.new(:upload_file => params[:photo][:image])
...
end
# Model
class Photo < ActiveRecord::Base
require 'mime/types'
...
def upload_file=(data)
data.content_type = MIME::Types.type_for(data.original_filename).to_s
self.image = data
end
end
精彩评论