Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6093881
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:36:44+00:00 2026-05-23T12:36:44+00:00

I’m working on an iPhone application that involves uploading full photos from the camera

  • 0

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!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T12:36:45+00:00Added an answer on May 23, 2026 at 12:36 pm

    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:

    - (void)socketClose
    {
        [_inputStream setDelegate:nil];
        [_inputStream close];
        [_inputStream removeFromRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
        SCR_RELEASE_SAFELY(_inputStream);
    
        [_outputStream setDelegate:nil];
        [_outputStream close];
        [_outputStream removeFromRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
        SCR_RELEASE_SAFELY(_outputStream);
    
        SCR_RELEASE_SAFELY(_headerBuffer);
    }
    
    - (void)sendRequest
    {
        [self socketClose];
        SCR_RELEASE_SAFELY(_headerBuffer);
    
        if (!_shouldCancel)
        {
            NSString *httpMessage = [NSString stringWithFormat:@"POST upload.php HTTP/1.1\r\n"
                                     "Host:"
    #ifndef TESTBED
                                     " %@"
    #endif
                                     "\r\n"
                                     "User-Agent: MyApp/3.0.0 CFNetwork/534 Darwin/10.7.0\r\n"
                                     "Content-Length: %d\r\n"
                                     "Accept: */*\r\n"
                                     "Accept-Language: en-us\r\n"
                                     "Accept-Encoding: gzip, deflate\r\n"
                                     "Content-Type: application/x-www-form-urlencoded\r\n"
                                     "Connection: keep-alive\r\n\r\n"
                                     "data="
    #ifndef TESTBED
                                     , [self.serverUrl host]
    #endif
                                     , _bytesToUpload];
    
            NSString *key = @"data=";
            NSData *keyData = [key dataUsingEncoding:NSASCIIStringEncoding];
            _bytesToUpload -= [keyData length];
            _bytesToUpload = MAX(0, _bytesToUpload);
    
            _headerBuffer = [[NSMutableData alloc] initWithData:[httpMessage dataUsingEncoding:NSUTF8StringEncoding]];
    
            _writtenDataBytes = 0;
    
            CFStreamCreatePairWithSocketToHost(kCFAllocatorDefault
                                               , (CFStringRef)[self.serverUrl host]
    #ifdef TESTBED
                                               , 8888
    #else
                                               , 80
    #endif
                                               , (CFReadStreamRef *)(&_inputStream)
                                               , (CFWriteStreamRef *)(&_outputStream));
    
            [_inputStream setDelegate:self];
            [_outputStream setDelegate:self];
    
            [_inputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
            [_outputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
    
            [_inputStream open];
            [_outputStream open];
        }
    }
    
    - (void)stream:(NSStream *)theStream handleEvent:(NSStreamEvent)streamEvent
    {
        if (_outputStream == theStream)
        {
            switch (streamEvent)
            {
                case NSStreamEventOpenCompleted:
                {
                    [self regenerateTimeoutTimer];
                    break;
                }
                case NSStreamEventHasSpaceAvailable:
                {
                    SCR_RELEASE_TIMER(_timeoutTimer);
                    NSInteger length = _headerBuffer.length;
    
                    if (length > 0)
                    {
                        NSInteger written = [_outputStream write:(const uint8_t *)[_headerBuffer bytes] maxLength:length];
                        NSInteger rest = length - written;
    
                        if (rest > 0)
                        {
                            memmove([_headerBuffer mutableBytes], (const uint8_t *)[_headerBuffer mutableBytes] + written, rest);
                        }
    
                        [_headerBuffer setLength:rest];
                    }
                    else
                    {
                        const uint8_t *dataBytes = [_data bytes];
    
                        while ([_outputStream hasSpaceAvailable] && (_writtenDataBytes < _bytesToUpload))
                        {
                            NSInteger written = [_outputStream write:dataBytes
                                                           maxLength:MIN(_dataLength, _bytesToUpload - _writtenDataBytes)];
    
                            if (written > 0)
                            {
                                _writtenDataBytes += written;
                            }
                        }
                    }
    
                    [self regenerateTimeoutTimer];
    
                    break;
                }
                case NSStreamEventErrorOccurred:
                {
                    SCR_RELEASE_TIMER(_timeoutTimer);
                    [self reportError:[theStream streamError]];                
                    break;
                }
                case NSStreamEventEndEncountered:
                {
                    SCR_RELEASE_TIMER(_timeoutTimer);
                    [self socketClose];
                    break;
                }
            }
        }
        else if (_inputStream == theStream)
        {
            switch (streamEvent)
            {
                case NSStreamEventHasBytesAvailable:
                {
                    SCR_RELEASE_TIMER(_timeoutTimer);
    
                    /* Read server response here if you wish */
    
                    [self socketClose];
    
                    break;
                }
                case NSStreamEventErrorOccurred:
                {
                    SCR_RELEASE_TIMER(_timeoutTimer);
                    [self reportError:[theStream streamError]];
                    break;
                }
                case NSStreamEventEndEncountered:
                {
                    SCR_RELEASE_TIMER(_timeoutTimer);
                    [self socketClose];
                    break;
                }
            }
        }
    }
    

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
Basically, what I'm trying to create is a page of div tags, each has
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I am currently running into a problem where an element is coming back from
I have a bunch of posts stored in text files formatted in yaml/textile (from
I have a text area in my form which accepts all possible characters from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.