[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

WEBRick: Problem to get the multipart/form-data decoded correctly.

Robert Dober

8/9/2007 3:18:00 PM

Hi list

I have to admit that I feel this is a stupid question, but two days of
Web search(1) and trials with WEBRick and CGI did not bring me any
closer.
Here is the problem:

I am uploading files to my Webrick server via the standard HTTP method:
<form method="POST" enctype="multipart/form-data">
<input type="file" name="data" /><input type="submit" /></form>

the Webrick do_POST handler than has the multipart/form-data in his req.body.

As astonishing as that sounds, I have not found a way to get the
file's content out of this.
I am sure there should be an easy way.

BTW I have browsed the ML archives and there are some references to
CGI but I just could not glue it together :(

All help is appreciated.

Robert

(1) a badly known synonym for "googling" ;)
--
[...] as simple as possible, but no simpler.
-- Attributed to Albert Einstein

4 Answers

Arlen Cuss

8/9/2007 4:07:00 PM

0


> Here is the problem:
>
> I am uploading files to my Webrick server via the standard HTTP method:
> <form method="POST" enctype="multipart/form-data">
> <input type="file" name="data" /><input type="submit" /></form>
>
> the Webrick do_POST handler than has the multipart/form-data in his req.body.
>
> As astonishing as that sounds, I have not found a way to get the
> file's content out of this.
> I am sure there should be an easy way.

Here's something I found from Google. It may not be definitive, sorry,
but I think it can help!

http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-...

Arle.


Robert Dober

8/9/2007 4:17:00 PM

0

On 8/9/07, Arlen Christian Mart Cuss <celtic@sairyx.org> wrote:
>
> > Here is the problem:
> >
> > I am uploading files to my Webrick server via the standard HTTP method:
> > <form method="POST" enctype="multipart/form-data">
> > <input type="file" name="data" /><input type="submit" /></form>
> >
> > the Webrick do_POST handler than has the multipart/form-data in his req.body.
> >
> > As astonishing as that sounds, I have not found a way to get the
> > file's content out of this.
> > I am sure there should be an easy way.
>
> Here's something I found from Google. It may not be definitive, sorry,
> but I think it can help!
>
> http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-...
That was indeed one of my first hits and it was useful to get the form
right, please note however that he is not doing anything with the
uploaded data :(, just sending it back.

And this exactly where it hurts, I cannot glue the received data
(req.body) into CGI, which would seem to do the multipart/form-data
conversion just fine.

Actually I would not care to save the body as such into a file and
have an external converter do the job(1), if I only had such an
external converer :(.

Thx anyway
Robert
(1) even if not in Ruby, sorry for the OL in that case.
>
> Arle.
>
>
>


--
[...] as simple as possible, but no simpler.
-- Attributed to Albert Einstein

Pit Capitain

8/9/2007 11:02:00 PM

0

2007/8/9, Robert Dober <robert.dober@gmail.com>:
> I have to admit that I feel this is a stupid question, but two days of
> Web search(1) and trials with WEBRick and CGI did not bring me any
> closer. (...)

Bonsoir Robert.

Google didn't help me either, but I'm using a Ruby wiki called "Soks",
which runs on WEBrick and offers file uploads. Reading the code it
seems that the following should work:

upload_data = request.query["data"]
File.open(upload_data.filename, "wb") do |file|
upload_data.each_data do |data|
file << data.to_s
end
end

Take a look at WEBrick::HTTPUtils::FormData.

I haven't tested it, but I HTH.

Regards,
Pit

Robert Dober

8/10/2007 8:07:00 AM

0

On 8/10/07, Pit Capitain <pit.capitain@gmail.com> wrote:
> 2007/8/9, Robert Dober <robert.dober@gmail.com>:
> > I have to admit that I feel this is a stupid question, but two days of
> > Web search(1) and trials with WEBRick and CGI did not bring me any
> > closer. (...)
>
> Bonsoir Robert.
>
> Google didn't help me either, but I'm using a Ruby wiki called "Soks",
> which runs on WEBrick and offers file uploads. Reading the code it
> seems that the following should work:
>
> upload_data = request.query["data"]
> File.open(upload_data.filename, "wb") do |file|
> upload_data.each_data do |data|
> file << data.to_s
> end
> end
>
> Take a look at WEBrick::HTTPUtils::FormData.
>
> I haven't tested it, but I HTH.
>
> Regards,
> Pit

I knew it would be simple, but that simple!!!
Works like charm.
Merci beaucoup Pit, meine Dankbarkeit wird Dir für immer nachschleifen
(sorry folks for these old Viennese saying ;)
Robert
>


--
[...] as simple as possible, but no simpler.
-- Attributed to Albert Einstein