1

我正在尝试将大文件从 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] 已发送 32768 个字节,共 2316966 个字节
2012-07-30 12:42:20.754 BMP[3290:3503] 已发送 65536 个字节,共 2316966 个字节
2012-07-30 12:42:20.760 BMP[3290:3503] 已发送 98304 个字节,共 2316966 个字节
2012-07-30 12:42:20.765 BMP[3290:3503] 已发送 131072 个字节,共 2316966 个字节
2012-07-30 12:42:21.113 BMP[3290:3503] 已发送 133452 个字节,共 2316966 个字节
2012-07-30 12:42:21.351 BMP[3290:3503] 发送 136148 个字节,共 2316966 个字节
2012-07-30 12:42:21.610 BMP[3290:3503] 发送 138844 个字节,共 2316966 个字节
2012-07-30 12:42:21.940 BMP[3290:3503] 已发送 141540 个字节,共 2316966 个字节
2012-07-30 12:42:22.030 BMP[3290:3503] 发送 144236 个字节,共 2316966 个字节
2012-07-30 12:42:22.120 BMP[3290:3503] 发送 146932 个字节,共 2316966 个字节
2012-07-30 12:42:22.142 BMP[3290:3503] 已发送 149628 个字节,共 2316966 个字节
2012-07-30 12:42:22.170 BMP[3290:3503] 发送 152324 个字节,共 2316966 个字节
2012-07-30 12:42:22.209 BMP[3290:3503] 发送 155020 个 2316966 字节
2012-07-30 12:42:22.240 BMP[3290:3503] 已发送 157716 个字节,共 2316966 个字节
2012-07-30 12:42:22.488 BMP[3290:3503] 已发送 160412 个字节,共 2316966 个字节
2012-07-30 12:42:22.668 BMP[3290:3503] 已发送 163108 个字节,共 2316966 个字节
2012-07-30 12:42:22.900 BMP[3290:3503] 已发送 163840 个字节,共 2316966 个字节
2012-07-30 12:42:23.003 BMP[3290:3503] 已发送 167152 个字节,共 2316966 个字节
2012-07-30 12:42:23.141 BMP[3290:3503] 发送 171196 个字节,共 2316966 个字节
2012-07-30 12:42:23.181 BMP[3290:3503] 已发送 173892 个字节,共 2316966 个字节
2012-07-30 12:42:23.211 BMP[3290:3503] 发送 176588 个字节,共 2316966 个字节
2012-07-30 12:42:23.251 BMP[3290:3503] 已发送 179284 个字节,共 2316966 个字节
2012-07-30 12:42:23.303 BMP[3290:3503] 发送 181980 个字节,共 2316966 个字节
2012-07-30 12:42:23.353 BMP[3290:3503] 已发送 184676 个字节,共 2316966 个字节
2012-07-30 12:42:23.416 BMP[3290:3503] 已发送 187372 个字节,共 2316966 个字节

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

有任何想法吗?

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

4

2 回答 2

0

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

于 2012-07-30T16:58:31.750 回答
0

事实证明,iOS 限制上传超过 3G。我在 Apple 的任何地方都找不到此文档。

然而,亚马逊已经为 s# 框架解决了这个问题http://aws.amazon.com/articles/0006282245644577 AFNetworking 有一个开发分支正在开发它(2012 年 7 月 31 日)https://github.com/AFNetworking/AFNetworking/pull /418

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

祝以后遇到这种情况的人好运。

于 2012-07-31T14:59:56.203 回答