所有我的rails paper_clip图像都以“application / octet-stream”上传到Rails
哪个是问题。
如何在Rails中将内容/类型设置为正确的类型?图像/ png等,基于上传的实际图像?
由于
答案 0 :(得分:1)
嗯,一般情况下,您总是可以使用'mime / types'从上传的文件中检测出正确的mime类型:
# 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