Take the 2-minute tour ×

I am using the paperclip gem with Omniauth (with Facebook) in a Rails 3 app. All the profile pictures are saved to Amazon S3.

Now the problem I am encountering is that many of the images are saved as stringio.txt, resulting in duplicated images. That means, some of my users have profile images that are not their own.

It seems that these images also occur when the image itself is more than 10kb.

So far I've tried saving directly using open-uri

self.avatar = open(omniauth['user_info']['image'].sub("square","large"))

share|improve this question
add comment

3 Answers

up vote 4 down vote accepted

I found this solution :

In the model where I have the paperclip image

before_post_process :transliterate_file_name


  def transliterate_file_name
    extension = 'JPG'
    filename = photo_file_name
    self.photo.instance_write(:file_name, "#{filename}.#{extension}")

It work well but in my case, I also have images from regular forms, so I think it's weird to do that. If all the pictures are from Facebook, it will be perfect.

share|improve this answer
add comment

Just hash the filename using Digest::MD5.hexdigest in combination with some random value and maybe a timestamp.

share|improve this answer
Good idea! I'll give that a shot and report back shortly! Thanks you! –  Benjamin Tan Jul 24 '11 at 7:34
add comment

Another alternative in Paperclip >= 3.1.4 is this (instead of using open-uri)

  def avatar_remote_url=(url_value)
    self.avatar = URI.parse(url_value)
    # Assuming url_value is http://example.com/photos/face.png
    # avatar_file_name == "face.png"
    # avatar_content_type == "image/png"
    @avatar_remote_url = url_value

via https://github.com/thoughtbot/paperclip/wiki/Attachment-downloaded-from-a-URL

share|improve this answer
add comment

Your Answer


