Monday, March 9, 2009

Uploading Images from URL using Paperclip

I was searching for a way inside paperclip that uploads image from Url instead of File which is the normal behavior handled by Paperclip but I didn't find that

After too much search and trials, I reached to a solution that is easy to be implemented and handle all cases you can expect in this process

I am applying the solution inside my model but it is preferred to add a patch to Paperclip version to use so that the same logic be applied everywhere but this exercise is left for you to do

To check the code and how it evolved to handle all special cases, Please review my gist here

2 comments:

Martijn Lafeber said...

Hi!

Your fork almost works perfectly. However, it saves the files as "open-uri20100104-5141-180ufie-0." (without extension)

I believe this is the result of:

file = open(URI.parse(file_url))
send("#{name}=", file)

Unknown said...

This is exactly what I was looking for, since I wanted to let my users upload pictures via url, than just upload. But what about delayed job? Can I still do

before_source_post_process do |video|
if pictures.source_changed?
false
end
end

(To give where credit is due, that isn't my code, I got it from http://ezror.com/blog/index.shtml)