File cannot be converted to a string in cache.rb #482

newmana opened this Issue Oct 6, 2011 · 10 comments


None yet

8 participants


I was running code against master that works in 0.5.7.

When calling cache_stored_file! (on a stored file) I get the following exception:

TypeError: can't convert File into String
../bundler/gems/carrierwave-963ec4657446/lib/carrierwave/uploader/cache.rb:73:in `initialize'
../bundler/gems/carrierwave-963ec4657446/lib/carrierwave/uploader/cache.rb:73:in `new'
../bundler/gems/carrierwave-963ec4657446/lib/carrierwave/uploader/cache.rb:73:in `cache_stored_file!'

It seems that it's a CarrierWave file (CarrierWave::Storage::Fog::File) not a Ruby File.

CarrierWave member

Do you see anything between 0.5.7 and master that looks like it may be causing your issue?

Can you provide a failing test?


I will try and get to this in the next few days.


Hi -- we're running intoe the same bug. Using minimagick and Fog. I briefly scanned the code and suspect it's the new sanitize stuff returning a file, but that's just a wild guess.


Also can confirm that reverting to 0.5.7 fixes the bug :-)

CarrierWave member

Closing due to inactivity -- if you can provide a failing test case or more info, we can continue the discussion

@bensie bensie closed this Dec 19, 2011

We've run into the same issue, downgrading to 0.5.7 fixes the error. I did some exploratory debugging on 0.5.8 (fog 1.1.2), and Fog::Storage::AWS::File#body is returning a file object instead of file contents. I hope this helps.

(rdb:1) l
[68, 77] in /Users/jnimety/.rvm/gems/ruby-1.9.3-p0@control/gems/carrierwave-0.5.8/lib/carrierwave/uploader/cache.rb
   68        #
   69        # This is useful when about to process images. Most processing solutions
   70        # require the file to be stored on the local filesystem.
   71        #
   72        def cache_stored_file!
=> 73          sanitized = :tempfile =>,
   74            :filename => File.basename(path), :content_type => file.content_type
   76          cache! sanitized
   77        end
(rdb:1) e
TypeError Exception: can't convert File into String
(rdb:1) e
(rdb:1) p file.send(:file).class
(rdb:1) p file.send(:file).body

Just ran into this problem using CarrierWave 0.6.2 and fog (Amazon AWS). I was trying to run .recreate_versions! and got this error.

As a workaround, I did this:

p.remote_image_url = p.image_url

This downloaded and recreated the thumbnails I needed. Hope this helps someone.


I also see this using 0.6.2 and fog while running recreate_versions!. @jamonholmgren's workaround works for me, but I'd love to see an actual fix.


I had this problem. It was when I updated the image and the then run recreate_versions!

@user.update_attributes(params[:user]) # where params -> {user: {avatar: File...}}

I fixed via reloading the instance: @user.reload.avatar.recreate_versions!


Also have this issue, with version .70 will try and get more details as I have them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment