I just wanted to know how one would go about uploading a remote file url using Carrierwave in the Rails console.
I tried the following without any luck. I presume it
Is work as:
url='http://host.domain/file.jpg'
time=Time.now.to_i.to_s
myfile=IO.sysopen("tmp/"+time+"_img."+url.split(".").last,"wb+")
tmp_img=IO.new(myfile,"wb")
tmp_img.write open(URI.encode(url)).read
if File.exist?("tmp/"+time+"_img."+url.split(".").last)
"tmp/"+time+"_img."+url.split(".").last
image = ActionDispatch::Http::UploadedFile.new(:tempfile => tmp_img, :filename => File.basename(tmp_img))
else
image=nil
end
@your_model.image=image
@your_model.save