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 --- <iktorn@gmail.com> wrote:>
> Is there a simple way of forcing file_column to download file from given
> (ex. in form) url instead of uploading it manualy?
>
> I know:
> http://blog.caboo.se/articles/2006/01/09/file_column-magick-and-versions
>
> require ''open-uri''
> Attachment.find_first.filename = open(url)
> if not working as expected... what is interesting is that:
>
> >> @a =
open(''http://www.google.com/intl/pl_ALL/images/logo.gif'')
> => #<StringIO:0x3c22390>
> >> @a = open(''
>
http://research.microsoft.com/~dcr/art/lamps/collage/P0002190.JPG'')
> => #<File:C:/DOCUME~1/VALUED~1/LOCALS~1/Temp/open-uri356.2>
>
> smaller files return StringIO
> larger - File (Tempfile to be specific)
>
> Any hints?
>
> --
> Posted via http://www.ruby-forum.com/.
> _______________________________________________
> Rails mailing list
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>
--
www.blogsaic.com
search, post, blog
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://wrath.rubyonrails.org/pipermail/rails/attachments/20060818/9a101c96/attachment.html