Search code examples
iphoneiosipadsoapmime

In iPad, how to build a MIME attachment from user drawing view/jpg so it can be upload via SOAP web service


I need to upload an user signature on ipad to server by SOAP web service. The signature will be a MIME attachment for the web service.

Need help to see how can the UIView or jpg on iOS can be converted to binary data MIME format so I can put it as part of the web service. Also, how the NSURLConnection can handle the binary data attachment. Thanks a lot.


Solution

  • If you need JPEG or PNG format data, you can use UIImageJPEGRepresentation or UIImagePNGRepresentation to convert a UIImage to an NSData object. If you need another format, you may be able to use CGImageDestination; a list of accepted UTIs can be obtained from CGImageDestinationCopyTypeIdentifiers. If you just need raw pixel data, draw the image to a CGBitmapImageContext and then read out the buffer using CGBitmapContextGetData; How to get pixel data from a UIImage (Cocoa Touch) or CGImage (Core Graphics)? may help you there.

    As far as NSURLConnection, posts are done using an NSData anyway. It's up to you to format the multipart/form-data structure or SOAP XML document correctly into an NSData, but then NSURLConnection will handle it fine.