File upload and mod-ruby

Hello everybody,

I am wondering if anyone can help me with implementing a file-upload
script using Apache2.0 and modruby1.1.1

lets say I have a form like this


what code should i use in upload.rb to grabe the filedata + filename
from the apache/modruby request. I want to save the file in a custom
directory.

Any help appreciated,
-g.

This is for apache 1.3.x not sure about 2 though:

···

On Mon, 2003-06-23 at 19:36, George Moschovitis wrote:

Hello everybody,

I am wondering if anyone can help me with implementing a file-upload
script using Apache2.0 and modruby1.1.1

lets say I have a form like this


what code should i use in upload.rb to grabe the filedata + filename
from the apache/modruby request. I want to save the file in a custom
directory.


require ‘cgi’
cgi = CGI.new() # New CGI object

myfile = cgi.params[‘myfile’].first.path


myfile is the file name which you can sue for File.new(myfile)

you might have to look at the http.conf

... RubySafeLevel 0 ...

in particular RubySafeLevel if you run into permission
errors/exceptions.

Sacha

Any help appreciated,
-g.

Sacha Schlegel

4 Warwick Str, 6102 St. James, Perth, Australia
sacha@schlegel.li www.schlegel.li
public key: www.schlegel.li/sacha.gpg

Sacha Schlegel wrote:

···

On Mon, 2003-06-23 at 19:36, George Moschovitis wrote:

Hello everybody,

I am wondering if anyone can help me with implementing a file-upload
script using Apache2.0 and modruby1.1.1

lets say I have a form like this


what code should i use in upload.rb to grabe the filedata + filename
from the apache/modruby request. I want to save the file in a custom
directory.

This is for apache 1.3.x not sure about 2 though:


require ‘cgi’
cgi = CGI.new() # New CGI object

myfile = cgi.params[‘myfile’].first.path


myfile is the file name which you can sue for File.new(myfile)

you might have to look at the http.conf

... RubySafeLevel 0 ...

in particular RubySafeLevel if you run into permission
errors/exceptions.

You should consider not lowering your safe level as there could be lots
of exploits in any file handling code if you are not very careful. I
recommend at least safe level 1 and 2 wouldn’t hurt either if you have
world writable locations…

See http://rubycentral.com/book/taint.html for information on taint levels.

/Anders


dc -e
4ddod3dddn1-89danrn10-dan3+ann6dan2an13dn1+dn2-dn3+5ddan2/9+an13nap

require ‘cgi’
cgi =3D CGI.new() # New CGI object

myfile =3D cgi.params[‘myfile’].first.path

thanks for the info, i was wondering if libapreq support will be added
to mod_ruby anytime soon.

regards,
George Moschovitis

Navel

Hi Sacha,

i tried it, ie my html is:


and the ruby handler is:

file = cgi[“myfile”].first

but it returns a String for file and not a structure i can query liek this:

file.local_path
file.original_filename
file.content_type

am i missing something?

(I am using apache2.0/worker-mpm and modruby1.1.1)

thanks in advance,
George Moschovitis

i tried it, ie my html is:

Try it with

  <form action='upload.rb' method='post'>

   <form action='upload.rb' method='post' enctype='multipart/form-data'>

    <input type='file' name='myfile'/><br/>

Guy Decoux

oops my mistake, thanx!
George Moschovitis