Showing posts with label ruby form upload. Show all posts
Showing posts with label ruby form upload. Show all posts

Wednesday, February 10, 2010

Multipart form data post through ruby script

Well its been long I blogged but better late than never... :)))
Been busy with projects, visit to India etc etc ... I can come up with a long list of excuses but none of them will be procrastinating ... hehehe

I forced my self out of hibernation to blog about a recent (strange ??) problem I faced.
In one of my projects, I came across a fairly common requirement to upload a file (multipart form-data post) through a ruby script. Pretty simple huhhh!

Unfortunately I was stumped to find that net/http library does not support it (still dont believe it!!). The documentation is very poor and it took me sometime to figure out net/http treats them all as string. CRAP !!!.

Some nice libraries eg: rest_client, httpclient, curb etc.. do a decent job in terms of posting the file, but they all mess with either creating incorrect boundaries for multi-part form or mess with content_length header of form-post

My requirement was to make http post call (multipart form data post) to Domino server. The domino app was very particular about content_length header, which is where I faced the biggest hurdle in using them.

Left with no choice, rolled up my sweet multipart form post.

Sharing with you all ruby-multipart-post.

How to use ==> here

Any feedback, most welcome ...

Enjoy !!!