Using Paperclip, I want to grab an image from a URL like this:
require 'open-uri'
user.photo = open(url)
The problem is that I then wind up with a filename like ‘open-uri20110915-4852-1o7k5uw’. Is there any way I can change the filename on user.photo?
As an added twist, Paperclip is storing my files on S3, so it’d be even better if I could set the filename I want in the initial assignment, so images get uploaded to the right S3 key. Something like this:
user.photo = open(url), :filename => URI.parse(url).path
You can write the filename back to your instance via:
So if your source URL is like:
You can first parse the name from the URL (to get
foo.jpg) and then write it back to the instance using the aboveinstance_writemethod.