# WEBRick: Problem to get the multipart/form-data decoded corr

**URL:** <https://www.ruby-forum.com/t/webrick-problem-to-get-the-multipart-form-data-decoded-corr/111664>\
**Category:** Ruby\
**Created:** [August 9, 2007, 5:19pm UTC](https://www.ruby-forum.com/t/webrick-problem-to-get-the-multipart-form-data-decoded-corr/111664 "2007-08-09T17:19:17Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![flatekmonkey](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/e8c25b/32.png) [@flatekmonkey](https://www.ruby-forum.com/u/flatekmonkey)\
**Post date:** [August 9, 2007, 5:19pm UTC](https://www.ruby-forum.com/t/webrick-problem-to-get-the-multipart-form-data-decoded-corr/111664/1 "2007-08-09T17:19:17Z")

</div>

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:

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” 😉

---

<div class="post-metadata">

**Author:** ![flatekmonkey](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/e8c25b/32.png) [@flatekmonkey](https://www.ruby-forum.com/u/flatekmonkey)\
**Post date:** [August 9, 2007, 6:08pm UTC](https://www.ruby-forum.com/t/webrick-problem-to-get-the-multipart-form-data-decoded-corr/111664/2 "2007-08-09T18:08:24Z")

</div>

> 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-talk/94785](http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/94785)

Arle.

---

<div class="post-metadata">

**Author:** ![flatekmonkey](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/e8c25b/32.png) [@flatekmonkey](https://www.ruby-forum.com/u/flatekmonkey)\
**Post date:** [August 9, 2007, 6:18pm UTC](https://www.ruby-forum.com/t/webrick-problem-to-get-the-multipart-form-data-decoded-corr/111664/3 "2007-08-09T18:18:26Z")

</div>

On 8/9/07, Arlen Christian Mart C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > 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-talk/94785](http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/94785)  
> 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.

---

<div class="post-metadata">

**Author:** ![flatekmonkey](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/e8c25b/32.png) [@flatekmonkey](https://www.ruby-forum.com/u/flatekmonkey)\
**Post date:** [August 10, 2007, 1:02am UTC](https://www.ruby-forum.com/t/webrick-problem-to-get-the-multipart-form-data-decoded-corr/111664/4 "2007-08-10T01:02:15Z")

</div>

2007/8/9, Robert D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> 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

---

<div class="post-metadata">

**Author:** ![flatekmonkey](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/e8c25b/32.png) [@flatekmonkey](https://www.ruby-forum.com/u/flatekmonkey)\
**Post date:** [August 10, 2007, 10:07am UTC](https://www.ruby-forum.com/t/webrick-problem-to-get-the-multipart-form-data-decoded-corr/111664/5 "2007-08-10T10:07:50Z")

</div>

On 8/10/07, Pit C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> 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

---

<div class="post-metadata">

**Author:** ![flatekmonkey](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/e8c25b/32.png) [@flatekmonkey](https://www.ruby-forum.com/u/flatekmonkey)\
**Post date:** [August 10, 2007, 1:28pm UTC](https://www.ruby-forum.com/t/webrick-problem-to-get-the-multipart-form-data-decoded-corr/111664/6 "2007-08-10T13:28:24Z")

</div>

I thought I share the outcome of this, a very primitive file server we  
need for some file transfer for folks caught behind a firewall and a  
mean Proxy. Only https passes.  
This might be useful for some low to medium traffic transfers.  
I will use it on demand only, it is not really tested and there might  
(there are for sure) some security issues. I have checked the most  
obvious.

Runs on any system you can execute `df -k` in your Ruby code (that  
part can be commented out if one needs to do so).  
Hope this might be helpful in case somebody searches the archives for

multipart/form-data File upload WEBrick File Server

Cheers  
Robert
