# WWW::Mechanize and file uploading

**URL:** <https://www.ruby-forum.com/t/www-mechanize-and-file-uploading/56319>\
**Category:** Ruby\
**Created:** [March 30, 2006, 6:00am UTC](https://www.ruby-forum.com/t/www-mechanize-and-file-uploading/56319 "2006-03-30T06:00:44Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mgreenly](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/85f322/32.png) [@mgreenly](https://www.ruby-forum.com/u/mgreenly)\
**Post date:** [March 30, 2006, 6:00am UTC](https://www.ruby-forum.com/t/www-mechanize-and-file-uploading/56319/1 "2006-03-30T06:00:44Z")

</div>

Hello all, I am fairly new to Ruby and I am loving every minute of it.  
I’ve  
been doing a lot of reading on Ruby and I really like what I’ve seen  
thus  
far. I am in the process of converting some Perl WWW::Mechanize code to  
Ruby’s WWW::Mechanize. Everything was going smooth until the portion  
where  
I have to upload a file to the website.

Accessing page.forms[0].file\_uploads[0] returns the  
#\<WWW::FileUpload:0x21614ec @file\_data=nil, @file\_name=“Browse”,  
@name=“txtUploadFile”\> object. However, I cannot determine how to set  
the  
path to the file that I wish to upload (the value of the textbox).

I’ve tried setting @file\_data and @file\_name to  
‘/Users/michaelguterl/test.txt’ through the appropriate accessor method.  
But each time I try and submit the form the website throws a nasty ASP  
error. I know it is possible to do what I am trying to accomplish using  
this approach. I’m just a little lost on the Ruby implementation of  
WWW::Mechanize and trying to find anything on google is nearly  
impossible  
with all the Perl stuff out there.

Any help is appreciated.

Thanks,  
Michael G.

---

<div class="post-metadata">

**Author:** ![mgreenly](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/85f322/32.png) [@mgreenly](https://www.ruby-forum.com/u/mgreenly)\
**Post date:** [March 30, 2006, 10:05pm UTC](https://www.ruby-forum.com/t/www-mechanize-and-file-uploading/56319/2 "2006-03-30T22:05:29Z")

</div>

In an attempt to provide some more useful information, here’s the output  
of  
mechanize.

I, [2006-03-29T21:56:02.225949 #5776] INFO – : POST:  
[http://www.censored.com/Manager/Upload/](http://www.censored.com/Manager/Upload/)  
upload\_1.asp?uploadType=callList&ftp=0&uploadLink=219601&CampLink=56458&ProjLink=20719&PID=477&OBS=&EBR=0&natlListLink=0

D, [2006-03-29T21:56:02.311599 #5776] DEBUG – : query:  
{“rdoFileType”=\>“0”,  
“txtZipPassword”=\>“”, “selDelimiter”=\>“Delimiter…”, “txtRecLen”=\>“”}  
D, [2006-03-29T21:56:02.312981 #5776] DEBUG – : request-header: accept  
=\>  
_/_  
D, [2006-03-29T21:56:02.314092 #5776] DEBUG – : request-header:  
content-type =\> application/x-www-form-urlencoded

Here’s the webserver’s exact response.

=\> #\<WWW::Page:0x20c6b04 @response=#\<Net::HTTPOK 200 OK readbody=true\>,  
@cookies=[], @uri=#\<URI::HTTP:0x106388e URL:  
[http://www.censored.com/Manager/Upload/upload\_1.asp?uploadType=callList&ftp=0&uploadLink=219601&CampLink=56458&ProjLink=20719&PID=477&OBS=&EBR=0&natlListLink=0](http://www.censored.com/Manager/Upload/upload_1.asp?uploadType=callList&ftp=0&uploadLink=219601&CampLink=56458&ProjLink=20719&PID=477&OBS=&EBR=0&natlListLink=0)\>,  
@code=“200”, @body=“ **WebServer ProcessRequest error**  
006~ASP  
0243~Cannot use IStream on Request~Cannot use IStream on Request object  
after using Request.Form collection or Request.BinaryRead. (  
SoftArtisans.FileUpEe.1)”, @watch\_for\_set=nil\>

I don’t know much about what’s going on behind the scenes here, but the  
only  
thing apparent to me is the lack of anything related to the FileUpload  
in  
the query hash. Again, let me reiterate, I’m not sure what is going on  
behind the scenes, so that could be expected.

I’m going to keep hacking away as soon as I get home tonight, so I’ll  
post  
an update if I get anywhere.

Thanks,  
Michael G.
