ios, convert UIImage to a MultipartFile
<p>I want to send an image to web server which has RestFul api's. This is what I have in my backend. First RequestParam ecgImage is the image.</p>

<pre><code>@RequestMapping(value = "/ecgimage", method = RequestMethod.POST)
    public void profileImage(@RequestParam("ecgImage") MultipartFile formData,
            @RequestParam("heartRate") int heartRate,
            @RequestParam("dateTime") String dateTime,
            @RequestParam("mac") String mac, @RequestParam("qrs") String qrs,
            @RequestParam("result") String result) throws Exception {
    ......
}
</code></pre>

<p>I'm using UNIRest libary in ios for making restful calls and I'm hoping something like this would work</p>

<pre><code>UIImage *img = // this is the image that I want to send

NSDictionary* headers = @{@"Content-Type": @"application/x-www-form-urlencoded"};
NSMutableDictionary* parameters = [[NSMutableDictionary alloc] init];
[parameters setObject:[self.dateUtils convertNSDateToMMDDYYY:date] forKey:@"date"];
[parameters setObject:hr forKey:@"heartRate"];
[parameters setObject:hr forKey:@"result"];
[parameters setObject:qrs forKey:@"qrs"];
[parameters setObject:????????? forKey:@"ecgImage"];

[[UNIRest post:^(UNISimpleRequest *request) {
     [request setUrl:POstECGImage];
//   [request setHeaders:headers];
     [request setParameters:parameters];
}] asJsonAsync:^(UNIHTTPJsonResponse* response, NSError *error) {

}];
</code></pre>

<p>How do I send the image?</p>

<p>In android I used to have the image as a Bitmap and I send it like this.</p>

<pre><code>Bitmap bitmap = // contains the image

ByteArrayOutputStream baos = new ByteArrayOutputStream();
            bitmap.compress(Bitmap.CompressFormat.JPEG, 50, baos);
            multipartEntity.addPart("ecgImage",
                    new ByteArrayBody(baos.toByteArray(), "ecg.jpg"));
            multipartEntity.addPart("dateTime", new StringBody(dateTime));
            multipartEntity.addPart("heartRate",
                    new StringBody(String.valueOf(heartRate)));
            multipartEntity.addPart("qrs", new StringBody(String.valueOf(qrs)));
            multipartEntity.addPart("result", new StringBody(result));
            multipartEntity.addPart("mac", new StringBody(mac));
</code></pre>

<p>But I now in iOS all I've is a UIImage. So i tried searching "convert UIImage to ByteArrayBody" but didn't have any luck. What would be equivalent code in Objective-C</p>