views:

387

answers:

4

Hi,

I'm trying to build a PHP webservice for an iPhone project I'm developing. I need to be able to send an image (picture) to the webservice, where I'll then store this in a database. I also need to write a service that will, of course, return this data when requested.

I'm not sure where to start though. I've 'googled' for how I can build such a webservice but can find no good example of how this can be done. Does anyone have a code example or a url to a tutorial that might help?

Regards,

Jamie.

A: 

I don't know about the iPhone end of things, but the XML Schema Definition provides support for Base64 encoded data (and Hex encoded data) that will allow you to transport the image info over the Soap protocol.

Jordan S. Jones
+2  A: 

What you need to do is create a form processing script on your webserver, that will receive a "POST" from the iphone client. A simple example of doing this is available at http://www.w3schools.com/PHP/php_file_upload.asp using purely PHP.

However because you have the iphone as the client you might want to use the NSMutableURLRequest object to "POST" the image to the script that you have already setup on the server. You don't specify where the image is coming from, but you probably want to read this:

http://iphone.zcentric.com/2008/08/29/post-a-uiimage-to-the-web/

fret
A: 

As fret says, you need to build an HTTP POST request with the image data in a POST form.

I highly recommend All Seeing eye's ASIHTTPRequest framework for building the form. Specifically you want to use the ASIFormDataRequest class. You can retrieve the binary information from a UIImage using (for example) NSData *UIImageJPEGRepresentation(UIImage *image, CGFloat compressionQuality); and add this to the ASHFormDataRequest by sending an instance a -(void)setData:(NSData *)data forKey:(NSString *)key message

Roger Nolan
A: 

Wondeful - thanks guys. The zcentric.com tutorial was superb; helped me along my way tremendously.

Regards,

Jamie.

badmanj