Paper_clip s3 - application / octet-stream?

时间:2010-10-25 03:23:58

标签: ruby-on-rails ruby-on-rails-3 paperclip mime-types

所有我的rails paper_clip图像都以“application / octet-stream”上传到Rails

哪个是问题。

如何在Rails中将内容/类型设置为正确的类型?图像/ png等,基于上传的实际图像?

由于

1 个答案:

答案 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