Cristi Cristi - 1 year ago 116
Ruby Question

carrierwave does not save content_type on Uploader

I have followed the instructions from

so I got:

require 'carrierwave/processing/mime_types'
class AssetFileUploader < CarrierWave::Uploader::Base
include CarrierWave::MimeTypes
process :set_content_type

but after a file upload the content_type is not updated.

I have a AssetInfo model with a uploader AssetFileUploader mounted on

:file attribute
class AssetInfo < ActiveRecord::Base
mount_uploader :file, AssetFileUploader

The params contain:

... "file"=># @headers="Content-Disposition: form-data; name=\"asset[asset_info_attributes][file]\"; filename=\"img.jpg\"\r\nContent-Type: image/jpeg\r\n"> ...

After the file upload I try in the console:

=> < CarrierWave::SanitizedFile:0x34b1c @original_filename=nil @content_type=nil @file="/home/reea/projects/ruby/learning_cms/public/uploads/asset_info/file/20/img.jpg">

=> nil

Answer Source

Carrierewave says they will deprecate this feature in the future and advise to use the Carrierwave::SanitizedFile instead

There's also an override method attached to this method

Maybe that can give you direction.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download