我正在使用载波上传图像。我遇到的问题是 content_type 没有保存到数据库中。我可以看到 content_type 被传递到请求中(如下所示),但它似乎没有进入数据库。
上传.rb
class Upload < ActiveRecord::Base
mount_uploader :file, FileUploader
attr_accessible :file
end
文件上传器.rb
require 'carrierwave/processing/mime_types'
class FileUploader < CarrierWave::Uploader::Base
include CarrierWave::MimeTypes
storage :fog
process :set_content_type
end
uploads_controller.rb
def create
@upload = Upload.new params[:upload]
if @upload.save
render :json => @upload
end
end
架构.rb
create_table "uploads", :force => true do |t|
t.date "expired_at"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.string "file"
t.text "slug"
t.string "file_content_type"
end
POST 请求
Started POST "/uploads" for 127.0.0.1 at 2013-04-11 22:54:56 -0400
Processing by UploadsController#create as */*
Parameters: {"name"=>"IMG_0004.JPG", "authenticity_token"=>"00kuSJQvgkWmCo+bWBQQzhzwC2qWdsF6T3K6DLuv0l8=", "upload"=>{"file"=>#<ActionDispatch::Http::UploadedFile:0x007fcb34399570 @original_filename="IMG_0004.JPG", @content_type="image/jpeg", @headers="Content-Disposition: form-data; name=\"upload[file]\"; filename=\"IMG_0004.JPG\"\r\nContent-Type: image/jpeg\r\n", @tempfile=#<File:/var/folders/9f/zccg30y961g1kl0zc_kzkfw00000gn/T/RackMultipart20130411-90625-1je1uyu>>}}