반송파를 사용하여 이미지를 업로드하고 있습니다. 문제는 content_type이 데이터베이스에 저장되지 않는다는 것입니다. content_type이 요청에 전달되는 것을 볼 수 있지만 (아래에서 볼 수 있듯이) DB에 전달하지 않는 것 같습니다.반송파가 설정되지 않았습니다. content_type
upload.rb
class Upload < ActiveRecord::Base
mount_uploader :file, FileUploader
attr_accessible :file
end
file_uploader.rb
require 'carrierwave/processing/mime_types'
class FileUploader < CarrierWave::Uploader::Base
include CarrierWave::MimeTypes
storage :fog
process :set_content_type
end
def create
@upload = Upload.new params[:upload]
if @upload.save
render :json => @upload
end
end
uploads_controller.rb schema.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>>}}
가 작동하지 않습니다 테이블의 MIME 형식 필드가해야 –