copy_to with remote_url loses file extension #206

pietschy opened this Issue Jul 4, 2012 · 3 comments

3 participants



I'm using copy_to (as per the documentation) in conjunction with remote_url to get apache serving the images directly. The problem is that the copied images are being stored without the file extension and this is buggering the mime types.

So using:

image_accessor :mugshot do
  copy_to(:smaller_mugshot){|a| a.thumb('200x200#') }
image_accessor :smaller_mugshot

I end up with smaller_mugshot.remote_url being things like system/dragonfly/production/2012/06/27/17_44_27_999_dragonfly20120627_11395_1qw9wkz_0

I've started writing some custom thumbnail generation code that creates another temp file with the correct extension but it's a bit of a pain.

Is there an easy way to get the extension included on the thumbnail files?

Thanks & cheers


Hi @pietschy, did you ever find a solution to this issue? I'm running into a similar problem now. Thanks,



Hi @trystant,

In the end I used a hacky method to generate my own temp file and used that.

# This method safely generates a thumbnail with a real file extension 
# as dragonfly doesn't include one when generating thumbnails.
# This wouldn't be needed if Dragonfly::TempObject.new_tempfile' used the 
# image format if ext isn't defined.
def generate_temp_thumbnail(image, spec)
  thumb = image.thumb(spec)
  filename = "#{Rails.root.join('tmp', 'thumbs')}/#{image.basename}_#{thumb.width}x#{thumb.height}_#{rand(10000)}.#{image.format}"

And then used it:

image_accessor :cover_image_master do
    copy_to(:cover_image) { |a| generate_temp_thumbnail(a, THUMB_SPEC) }

I probably should have submitted a patch but I was in a hurry and very new to both ruby and rails.



sorry for the delay getting back - this won't be a problem with the release of version 1.0 due to refactoring work I've been doing - cheers

@markevans markevans closed this Aug 21, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment