AfNetworking上传停止并最终仅通过3G超时

时间:2012-07-30 16:46:53

标签: iphone ios upload 3g afnetworking

我正在尝试将大型文件从iOS上传到服务器

我的代码启动webservce,上传~180000字节后,它会挂起,等待,并最终超时。

正如代码目前所在。 (我已经改变了很多尝试进行故障排除)

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];

输出始终如下所示

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

然后几分钟后我从AFNetworking获得了超时

任何想法?

更新::: 显然它只在通过3G上传时发生

2 个答案:

答案 0 :(得分:0)

这似乎更像是服务器端问题。您是否检查过服务器是否正确接收了数据?

答案 1 :(得分:0)

事实证明iOS限制上传3G。我无法在Apple的任何地方找到此文件。

然而 亚马逊为s#http://aws.amazon.com/articles/0006282245644577解决了这个问题 AFNetworking有一个开发分支(7/31/12)https://github.com/AFNetworking/AFNetworking/pull/418

过时的ASIHTTPRequest处理它,是我唯一的希望http://allseeing-i.com/ASIHTTPRequest/How-to-use#throttling_bandwidth

祝所有遇到此事的人好运。