this is quite easy I have done it at http://www.blogsaic.com/
sign up and upload a tile to see how it works
you can’t send the url to file column
but, what you can do is upload a file from a url to the same table
column
using open-uri
you have to do a bit more than just Attachment.find_first.filename =
open(url)
my way is not very optimised, but it does the trick…for now because I
still want to retain the original file name, and open(url) only uses
some
cgi generated name
in the tmp directory
but basically the below code checks if the url is formatted correctly in
the
http// format
then it strips the file name from the full file path posted in the
upload
form
then it copies the temp file to the file_column with @tile.img_name =
File.new(ff.path)
you’ll need to add these to your environment.rb to use the system/kernel
commands
#Needed for url uploads
require ‘open-uri’
require ‘ftools’
require ‘fileutils’
this is my upload action
@tile = Tile.new(params[:tile])
@tile.fk_tbl_user_id = @session[:user].id
orig = params[:tile][:img_path] ----------------- this is from
the
form at http://www.blogsaic.com/tile/
raise if not orig =~
/^(http|https)://[a-z0-9]+([-.]{1}[a-z0-9]+).[a-z]{2,5}(([0-9]{1,5})?/.)?$/ix
logger.error "???????????? VALUE >> #{orig}"
response = false
#if good url format, get the file
tn = open(orig)
filename = orig.split("/")
tp = tn.path
nf = File.new(tp)
nf_path = File.split(nf.path)
f = "#{nf_path[0]}" << "/" << "#{filename.last}"
FileUtils.touch f
#sleep 2
ff = File.new("#{f}")
FileUtils.copy nf.path, ff.path
@tile.img_name = File.new(ff.path) #gold
rescue
if response == false
logger.error "???????????? BAD URL >> #{orig}"
end
end
else
etc etc then do your normal save stuff…
@tile.save etc etc
http://www.blogsaic.com/
I have some extra stuff that checks if the file is from teh file system
or a
URL…but I hope this is enough to get you in the right direction
cheers
dion
On 8/18/06, Wiktor — [email protected] wrote:
–
Posted via http://www.ruby-forum.com/.
Rails mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails
–
www.blogsaic.com
search, post, blog