Importing images with file_column over http?

I haven’t cracked the source of file_column just yet - but has anyone
out a way to snag images via URL instead of a file upload?

Optimally I’d like to have my clients be able to upload a file, or enter
a URL to store as file on the system.

Any/all help would be cool.

On Jun 21, 2006, at 8:15 PM, subimage interactive wrote:

seth at subimage interactive

Rails mailing list
[email protected]

Try something like this:

require ‘open-uri’

def fetch_resource(options={})[:to], “wb”) { |f| f.write open(options
[:from]).read }

fetch_resource :from => “”,
:to => “#{RAILS_ROOT}/public/assets/


Thanks EZ, but that’s the easy part :slight_smile:

The hard part is getting file_column to take it and do its magic. Guess
need to look into the source. I saw a BaseUploadedFile::assign that
might be
useful in combination with your code.

That got me on the right track…here’s my full controller method.
is pre-populated most of the time by my data import scripts.

Hopefully someone else finds this snippet useful.

Imports an image from the item’s url and feeds it into the image



file_column automagically resizes it, and we set the item to use the


uploaded image

def import_image
require ‘open-uri’

@item = Item.find(params[:id])
if [email protected]
  redirect_to :back and return

import_from = @item.image_url.clone
chop_position = import_from.rindex("/")

file_name = import_from[chop_position+1..import_from.size-1]

save_to = "#{RAILS_ROOT}/public/item/image_upload/test/#{file_name}", "wb") { |f| f.write open(import_from).read }

@item.image_upload =
@item.image_use_option = 2

redirect_to :action => 'edit', :id => @item


This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs