I am attempting to upload a large file from iOS to a server
My code starts the webservce and after uploading ~180000 bytes it hangs, waits, and eventually times out.
As the code currently sits. (I have changed alot trying to troubleshoot)
AFHTTPClient *uploadClient = [[AFHTTPClient alloc] initWithBaseURL:[NSURL URLWithString:k_WebService_Root]];
NSMutableDictionary *parameters = [NSMutableDictionary dictionaryWithObjectsAndKeys:
@"secret" , @"Token",
nil];
NSDictionary *requestObject = [NSDictionary dictionaryWithObject:parameters forKey:@"request"];
NSString *endpoint = [self makeEndpointWithService:k_ServiceEndpoint_Message andAction:k_WebService_Message_Upload];
NSMutableURLRequest *request = [uploadClient multipartFormRequestWithMethod:@"POST" path:endpoint parameters:requestObject constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
NSData *data = [NSData dataWithContentsOfFile: videoFile.path];
[formData appendPartWithFileData:data name:@"file" fileName:@"message.mov" mimeType:@"video/quicktime"];
}];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
[operation setUploadProgressBlock:^(NSInteger bytesWritten, long long totalBytesWritten, long long totalBytesExpectedToWrite) {
NSLog(@"Sent %lld of %lld bytes", totalBytesWritten, totalBytesExpectedToWrite);
}];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"Success");
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Fail\n%@", error);
}];
[operation start];
The Output always looks like this
2012-07-30 12:42:20.747 BMP[3290:3503] Sent 32768 of 2316966 bytes 2012-07-30 12:42:20.754 BMP[3290:3503] Sent 65536 of 2316966 bytes 2012-07-30 12:42:20.760 BMP[3290:3503] Sent 98304 of 2316966 bytes 2012-07-30 12:42:20.765 BMP[3290:3503] Sent 131072 of 2316966 bytes 2012-07-30 12:42:21.113 BMP[3290:3503] Sent 133452 of 2316966 bytes 2012-07-30 12:42:21.351 BMP[3290:3503] Sent 136148 of 2316966 bytes 2012-07-30 12:42:21.610 BMP[3290:3503] Sent 138844 of 2316966 bytes 2012-07-30 12:42:21.940 BMP[3290:3503] Sent 141540 of 2316966 bytes 2012-07-30 12:42:22.030 BMP[3290:3503] Sent 144236 of 2316966 bytes 2012-07-30 12:42:22.120 BMP[3290:3503] Sent 146932 of 2316966 bytes 2012-07-30 12:42:22.142 BMP[3290:3503] Sent 149628 of 2316966 bytes 2012-07-30 12:42:22.170 BMP[3290:3503] Sent 152324 of 2316966 bytes 2012-07-30 12:42:22.209 BMP[3290:3503] Sent 155020 of 2316966 bytes 2012-07-30 12:42:22.240 BMP[3290:3503] Sent 157716 of 2316966 bytes 2012-07-30 12:42:22.488 BMP[3290:3503] Sent 160412 of 2316966 bytes 2012-07-30 12:42:22.668 BMP[3290:3503] Sent 163108 of 2316966 bytes 2012-07-30 12:42:22.900 BMP[3290:3503] Sent 163840 of 2316966 bytes 2012-07-30 12:42:23.003 BMP[3290:3503] Sent 167152 of 2316966 bytes 2012-07-30 12:42:23.141 BMP[3290:3503] Sent 171196 of 2316966 bytes 2012-07-30 12:42:23.181 BMP[3290:3503] Sent 173892 of 2316966 bytes 2012-07-30 12:42:23.211 BMP[3290:3503] Sent 176588 of 2316966 bytes 2012-07-30 12:42:23.251 BMP[3290:3503] Sent 179284 of 2316966 bytes 2012-07-30 12:42:23.303 BMP[3290:3503] Sent 181980 of 2316966 bytes 2012-07-30 12:42:23.353 BMP[3290:3503] Sent 184676 of 2316966 bytes 2012-07-30 12:42:23.416 BMP[3290:3503] Sent 187372 of 2316966 bytes
And then after a few minutes i get a Timeout from AFNetworking
Any Ideas?
UPDATE ::: Apparently it only happens while uploading over 3G
It turns out iOS limits uploads over 3G. I cannot find this documented anywhere from Apple.
However Amazon has solved it for s# framework http://aws.amazon.com/articles/0006282245644577 AFNetworking has a dev branch working on it (7/31/12) https://github.com/AFNetworking/AFNetworking/pull/418
ASIHTTPRequest while out of date handles it and is my only hope http://allseeing-i.com/ASIHTTPRequest/How-to-use#throttling_bandwidth
Good Luck to anyone who encounters this in the future.