使用AFNetworking在iOS上上传大文件 – 错误请求超时

我面临着下一个问题。 在我的项目中,我正在使用AFNetworking进行所有networking操作。 其中之一是上传video的服务器。 然后我试图上传大型video(大约100 Mb),我得到请求超时错误。

错误域= NSURLErrorDomain代码= -1001“请求超时。” 的UserInfo = 0x15641b30
{NSErrorFailingURLStringKey = http://server.name/path,NSErrorFailingURLKey = http://server.name/path,NSLocalizedDescription =请求超时,NSUnderlyingError = 0x16f7a000“请求超时。”}

现在我正在使用AFNetworking v1.3.3,而且我不能使用v2.0,因为需要iOS5支持。

当上传刚刚开始,上传进度看起来很好(我通过UploadProgressBlock看到它)。 但是在几兆字节之后,上传开始变慢,然后停止。 SpeedTest给我上传5Mbps,下载5Mbps。

通过networking浏览器上传video工作正常,所以我不认为这是服务器问题。

这是我的代码:

AFHTTPClient *client = [AFHTTPClient clientWithBaseURL: [NSURL URLWithString:@"http://server.name/"]]; NSString *appid = [[self class] sharedProvider].ApplicationId; ALAssetRepresentation *representaion = [videoData.videoAsset defaultRepresentation]; NSURL *url = [BRDataProvider getVideoAssetURLForTempFileWithAsset: videoData.videoAsset]; AFHTTPRequestOperation *operation; if (url) { NSMutableURLRequest *request = [client multipartFormRequestWithMethod:@"POST" path:@"some/path" parameters:nil constructingBodyWithBlock:^(id<AFMultipartFormData> formData) { NSData *hdnADCID = [appid dataUsingEncoding:NSUTF8StringEncoding]; [formData appendPartWithFormData:hdnADCID name:@"hdnADCID"]; NSData *txtTitle = [videoData.title dataUsingEncoding:NSUTF8StringEncoding]; [formData appendPartWithFormData:txtTitle name:@"txtTitle"]; NSData *txtDescription = [videoData.description dataUsingEncoding:NSUTF8StringEncoding]; [formData appendPartWithFormData:txtDescription name:@"txtDescription"]; NSData *txtKeywords = [videoData.tags dataUsingEncoding:NSUTF8StringEncoding]; [formData appendPartWithFormData:txtKeywords name:@"txtKeywords"]; [formData appendPartWithFileURL:url name:representaion.filename error:nil]; }]; [request setTimeoutInterval:600]; operation = [fliqzClient HTTPRequestOperationWithRequest:request success:^(AFHTTPRequestOperation *operation, id responseObject) { [[NSFileManager defaultManager] removeItemAtURL:url error:nil]; NSString *assetID = [operation.responseString stringByReplacingOccurrencesOfString:@"&\r\n" withString:@""]; assetID = [assetID stringByReplacingOccurrencesOfString:@"id= " withString:@""]; videoData.assetId = assetID; [BRDataProvider registerVideoWithInfo:videoData completion:^(id result, NSError *error) { block(result,error); }]; } failure:^(AFHTTPRequestOperation *operation, NSError *error) { NSLog(@"error - %@", error); block(nil,error); [[NSFileManager defaultManager] removeItemAtURL:url error:nil]; }]; [operation setUploadProgressBlock:^(NSUInteger bytesWritten, long long totalBytesWritten, long long totalBytesExpectedToWrite) { NSLog(@"bytesWritten - %d, totalBytesWritten - %lld, totalBytesExpectedToWrite - %lld", bytesWritten, totalBytesWritten, totalBytesExpectedToWrite); }]; [client enqueueHTTPRequestOperation:operation]; } else { NSError *error = [NSError errorWithDomain:kBRErrorDomainOwnDomain code:0 userInfo:@{NSLocalizedDescriptionKey:kPreprocessingErrorUploadVideoMessage}]; block(nil, error); } 

也许有人知道如何解决这个问题? 谢谢你的帮助!

我有类似的问题AFNetworking:NSURLErrorDomain代码= -1001“请求超时。” 当从外部服务器检索并且设备位于连接到WAN的路由器的子网上时,该请求完美工作(192.168.1.0子网1 – > WAN)。 但是,如果连接到与连接到WAN的路由器相连的子网,请求将失败,并显示以上消息(192.168.0.0 subnet-2 – > 192.168.1.0 subnet-1 – > WAN)。 所有的浏览器操作都通过子网-2正常工作,AFNetworking似乎连接但是收到一个超时。 我怀疑问题是与子网2路由器的configuration。