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

mycompuser

macrumors member
Original poster
May 8, 2012
37
0
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
Code:
curl --form file=@/Volumes/Untitled/fig1.png http://xxxx.com/upload
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 http://curl.haxx.se/mail/lib-2008-01/0322.html 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.
 

KoolStar

macrumors demi-god
Oct 16, 2006
825
9
Kentucky
Have you tried looking at a networking framework such as MKNetworkKit or ASINetwork to handle the uploading for you?
 

larswik

macrumors 68000
Sep 8, 2006
1,552
11
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.
 

mycompuser

macrumors member
Original poster
May 8, 2012
37
0
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.
 

Attachments

  • TestApp.zip
    92.3 KB · Views: 175
Last edited:
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.