# Mechanize Form File Upload

**URL:** <https://www.ruby-forum.com/t/mechanize-form-file-upload/194605>\
**Category:** Ruby\
**Created:** [September 7, 2010, 9:16pm UTC](https://www.ruby-forum.com/t/mechanize-form-file-upload/194605 "2010-09-07T21:16:51Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![tkeber](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/c37758/32.png) [@tkeber](https://www.ruby-forum.com/u/tkeber)\
**Post date:** [September 7, 2010, 9:16pm UTC](https://www.ruby-forum.com/t/mechanize-form-file-upload/194605/1 "2010-09-07T21:16:51Z")

</div>

Hi all,

I’m trying to upload a file to a Form in this way. My Question is, how  
to get the imagefile posted correctly.

def uploadpicture(username, password, imagepath)  
agent = Mechanize.new  
agent.post(“[http://www.somesite.com/](http://www.somesite.com/)”,  
{ ‘function’ =\> ‘picture2’,  
‘username’ =\> username,  
‘password’ =\> password,  
‘pict’ =\> ???,  
‘pict\_to’ =\> 0,  
‘pict\_type’ =\> 0,  
‘submit’ =\> ‘Send’ }) { |page| return page }  
end

Thanks and Regards,

T.

---

<div class="post-metadata">

**Author:** ![tkeber](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/c37758/32.png) [@tkeber](https://www.ruby-forum.com/u/tkeber)\
**Post date:** [September 8, 2010, 5:55am UTC](https://www.ruby-forum.com/t/mechanize-form-file-upload/194605/2 "2010-09-08T05:55:39Z")

</div>

> ```
> 'pict' => ????????,
> 
> ```

File.binread(‘pic.jpg’) ?
