File upload using curl.

Discussion in 'Mac Programming' started by mycompuser, Jan 10, 2013.

  1. mycompuser macrumors member

    May 8, 2012
    Hi All,

    One of the requirements of my cocoa app on Lion (using xcode) is to upload an file to an upload server as a "multipart/form-data" using HTTP POST.

    I achieve the upload using NSURLConnections when I am connected via ethernet.
    For some reason When I am connected via WiFi, the upload using NSURLConnection seems to fail (with an error 504).
    But when I try to upload the same file to the same URL using CURL the same succeeds.
    Not sure why this behavior is exhibited.

    I use the following curl command
    curl --form file=@/Volumes/Untitled/fig1.png
    I also get the response "Received 202946 bytes of file fig1.png" indicating that the upload was successful.
    Note: the url specified in the sample above is dummy.

    Now I am trying to implement the http upload using CURL programatically.

    I've tried using the sample provided in but unable to succeed in uploading.
    Also tried my hands on CurlHandle library but still no success.

    I might be missing something very silly.

    It might be too much to ask in a forum, but is it possible for some of you gurus to actually post an curl code which you know for sure does http post upload without giving any error.

    Thanks & Regards.
  2. KoolStar macrumors demi-god


    Oct 16, 2006
    Have you tried looking at a networking framework such as MKNetworkKit or ASINetwork to handle the uploading for you?
  3. larswik macrumors 68000

    Sep 8, 2006
    I asked about something similar in a few posts below. I could not get the ASINetwork stuff working? Downloading from the web is an easy task but uploading is a major pain. My code logs in successfully and then just hangs and does nothing?

    I am curious if you figure this out.
  4. mycompuser, Jan 13, 2013
    Last edited: Jan 13, 2013

    mycompuser thread starter macrumors member

    May 8, 2012
    Hi KoolStar,

    Thanks for the reply. Sorry for the delay to respond.

    I am not familiar with either of these networking framework.

    I managed to get the upload using Curlhandle working. Not sure why it was not working earlier.

    Have uploaded the test app which perform an HTTP POST and GET using CURLHandle.

    Hi larswik,

    Hope this test app helps you with the upload.

    Note: In the uploaded project, pls replace the place holders for upload and download URL strings with valid values.

    Attached Files:

Share This Page