Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

jagatnibas

macrumors regular
Original poster
Jul 28, 2008
126
0
I am needed to explore how to upload files to a server from iphone app. I do understand it needs NSURLConnection with proper parameters. But what would i have to do in my server side [apache/php] to be able to test this ?

also any example code for uploading in iphone will be helpful

thanks in advance and regards
Jagat
 
I think you will have better luck in a PHP Programming forum.

I guess you need to read the input stream to get a byte array with the file's data, and then either store that byte array in a database or save it to a file. In http://www.php.net/ you should find how to do it.
 
html

I think the way it works in php is more trivial. Html provides an upload attribute which takes care of sending the data to the server. I agree php code in the server might remain same, but how to emulate this html upload feature in my iphone app ?

regards
 
in essence, you have to create a multiform POST message using the NSURLRequest. the NSData file payload you are trying to upload would be appended to the POST contents as binary form data.

best way to figure out how your POST message should look like is to create an html form which requests a file for uploading, and write the server-side script that receives the file and stores it. once you make sure that works, use a proxy or port sniffer and see how a regular browser formats the raw POST request; you will have to format it identically with the iphone app. good luck.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.