Mini-Mallows: A Multi-Part Form Wrapper for Cocoa & iPhone
- 22nd October , 2008 by Sam in Cocoa, Objective-C, iPhone
- 3 comments

All I wanted was some simple code to POST an image to a web service from my iPhone project. No big deal, right? Apparently, not.
Based on my google search results many people we were wanting the same thing and just not finding it. There are a couple iphone development sites giving examples and some really old open-source projects but nothing really felt right to me. So being a good developer I hacked something together which works for me and posted it on GitHub.
Issuing standard GETs and POSTs with Cocoa is pretty easy, but I couldn’t find anything easy to make multi-part forms for POSTing. This is where mini-mallows comes in. Just make some Cocoa, add some mini-mallows (form fields & a file), and POST.
Easy.
Current status
This project was written to satisfy my need to POST a single image and related form fields from an iPhone app to a web service. It only allows for the addition of one file per request. I am very open to comments, patches, and ridicule.
Installation
Get the code from GitHub => a href=”http://github.com/sschroed/mini-mallows”>http://github.com/sschroed/mini-mallows
Copy the files MultipartForm.h and MultipartForm.m anywhere you like into your Xcode project.
Usage
First, add your standard #import.
Create a NSURL object as you’ll need to send that to Mini-Mallows.
Now create a MultipartForm object and a few form fields and a file. I really wanted to call the class MiniMallows but MultipartForm is easier on the eyes.
When you are done adding fields and the file you can get a fully formed NSMutableURLRequest object from Mini-Mallows.
All set so POST the form.


February 16th, 2009 at 12:22 am
I just grabbed the source from GitHub and tried to compile MultipartForm.m, but got errors. I changed line 113 from:
mpfFieldNameForFile = [fieldName release];
-to-
mpfFieldNameForFile = [fieldName retain];
Builds now.
July 24th, 2009 at 7:38 am
superb source on multipart posting. thanks for the help
November 25th, 2009 at 7:30 am
i have tried to change the timeout by changing in multipartform.m by giving [request setTimeOutInterva,l:10] but it is not getting timed out. please post a solutiong if possible.