Rails, paper clip, loading photos from a rake task?

How can I upload a file using paperclip through the console or into the rake command? I'm a little unsure how this works without a form. Has anyone dealt with this?


Update

So, I found this:

image = Image.new(:storage => File.open('/path/to/my/image.png', rb)) 

But I think this makes my question a little easier, say, my photo was online (in different domains), and I wanted to take it with a paper clip and convert it and upload it to my server. Is it possible to somehow give a File.open url?

+4
source share
3 answers

Take a picture.

 require 'open-uri' image = Image.new(:storage => open("http://path.to.the/image.png")) 

Worked when I tried it in my terminal, I just did:

 require 'open-uri' image = open("http://i.stack.imgur.com/qjKuQ.jpg") 

as a result:

 => #<File:/var/folders/Zo/ZoJYH-A6Eg8GQ3pV0fIyhU+++TU/-Tmp-/open-uri20101117-5813-1h64t5k> 
+6
source

However, it saves the files as "open-uri12345sdf-1301fp". (without extension) in the database. How to save the original file name in the photo_file_name field.

+1
source

This is a kind of hack that I think, but I just replicated the files using the ActionDispatch :: Http :: UploadedFile.new object in my migration and ran it that way.

+1
source

All Articles