iosobjective-cnsurlconnectionafnetworking3g-network

Mulipartpost NSURLConnection over 3G network problems


we have an iOS app that uploads images to a server using a multipart post. Everything is ok while using wifi, but on 3G for large images we are getting network errors.

On the client (iPhone):

I got a

Domain=NSURLErrorDomain Code=-1021 “request body stream exhausted”

based on this post I tried to use the AFNetwork library with that method but still got the same exact result.

On the server:

I have setup a proxy to see the request and I am getting

"Socket broken pipe"

usually after 740Kb have been transmitted

So, what am I doing wrong? Like I said over wifi everything works fine, and on 3G with small images is fine too.

The AFNetwork version code (stops transferring after 600 - 800 kb for large images):

AFHTTPClient *client = [[AFHTTPClient alloc] initWithBaseURL:self.baseURL];

        request = [client multipartFormRequestWithMethod:@"POST"
                                                                         path:nil
                                                                   parameters:nil
                                                    constructingBodyWithBlock:^(id<AFMultipartFormData> formData)
                                        {

                                            for (NSString* partType in self.parts) {
                                                if ([partType isEqualToString:@"jsonpart"]) {
                                                    [formData appendPartWithFormData:[self.parts objectForKey:partType] name:@"@json"];
                                                }
                                                else{ //is an image for sure
                                                    [formData appendPartWithFileData:[self.parts objectForKey:partType]
                                                                                name:partType
                                                                            fileName:[NSString stringWithFormat:@"%@-%d.jpg", partType, [partType hash]]
                                                                            mimeType:@"image/jpeg"];
                                                }

                                            }

                                            [formData throttleBandwidthWithPacketSize:kAFUploadStream3GSuggestedPacketSize delay:kAFUploadStream3GSuggestedDelay];
                                        }];

        AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];

        [client enqueueHTTPRequestOperation:operation];

Solution

  • Ok, after a lot of hours spent on this I finally got it. Nothing to do with the code, for some reason the company firewall is playing a role here. With the firewall turned off everything works fine. Strange, but that solves it, and is out of the iOS or code scope.