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

Closed
newmana opened this Issue Oct 6, 2011 · 10 comments

Projects

None yet

8 participants

@newmana

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.

@bensie
CarrierWave member

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

Can you provide a failing test?

@newmana

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

@tomharrisonjr

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.

@tomharrisonjr

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

@bensie
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
@jnimety

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 = SanitizedFile.new :tempfile => StringIO.new(file.read),
   74            :filename => File.basename(path), :content_type => file.content_type
   75  
   76          cache! sanitized
   77        end
(rdb:1) e StringIO.new(file.read)
TypeError Exception: can't convert File into String
(rdb:1) e file.read
#<File:/Users/jnimety/workspace/control/public/uploads/tmp/20120110-1345-85902-6240/KitchenSink.zip>
(rdb:1) p file.send(:file).class
Fog::Storage::AWS::File
(rdb:1) p file.send(:file).body
#<File:/Users/jnimety/workspace/control/public/uploads/tmp/20120110-1345-85902-6240/KitchenSink.zip>
(rdb:1)
@jamonholmgren

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
p.save

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

@abscondment

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.

@miry

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...}}
@user.avatar.recreate_versions!

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

@incorvia

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