I'm working on an iPhone application that involves uploading full photos from the camera (generally between 1.5 to 2.0 MB each) as well as their thumbnails (much smaller) to Amazon S3.
The thumbnails always successfully upload, but sometimes the full images don't, and when they fail, they fail with POSIX error code 12, aka ENOMEM. However, I've added debug code to print the amount of free memory when the error happens, and there's always quite a bit free, usually more than 100 MB.
Furthermore, the error crops up more often when the upload is happening over 3G and less when it's over wifi -- which seems strange, since the request isn't downloading much and the file being uploaded is already in memory (I've also tried streaming it from disk with no improvement).
I've tried uploading the file using NSURLConnection, the Foundation CFHTTP* functions, and the ASIHTTPRequest library, but regardless, the error happens with the same frequency. Even stranger, all my Googling has revealed is that end users sometimes get error code 12 from Safari -- I haven't seen any iOS developers mentioning it. I'm working with an inherited code base, so it's possible there's something wrong with it, but I'm not even sure what to look for. Any insight would be greatly appreciated!
Have resolved this error with using operation for request (
NSMutableUrlConnection
) with@autorelease{}
for main function. NSPOXIS appears only sometimes.The key to getting around this issue is to upload the file using a stream. When using NSMutableURLRequest, this can be accomplished using something similar to the following:
When using ASIHTTPRequest, streaming a file is accomplished with this:
The only way I was able to work around this issue, is using sockets directly and forming HTTP header manually. So my uploading code currently looks like this:
Although ASIHTTPRequest could work here, we decided to walk away from such dependencies both in order to get performance and to keep everything under our own control accurately. You can use Wireshark tool in order to debug this kind of things.