file upload

Discussion in 'iOS Programming' started by jagatnibas, Jul 16, 2009.

  1. jagatnibas macrumors regular

    Jul 28, 2008
    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
  2. sergio27 macrumors member

    Nov 2, 2008
    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 you should find how to do it.
  3. jagatnibas thread starter macrumors regular

    Jul 28, 2008

    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 ?

  4. drivefast macrumors regular

    Mar 13, 2008
    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.

Share This Page