AFNetworking
マルチパートPOSTを使用してファイルをWebサービスにアップロードするために使用しています。WiFiを使用する場合はすべて正常に機能しますが、3gを介してアップロードする場合、2メガバイトを超えるファイルのアップロードは失敗します。
私は2つのアプローチを試しましたが、どちらも送信された正確なバイト数で失敗します:1998848。1つまたは複数のファイルがそれよりも小さい場合、アップロードは成功します。
Amazon S3 SDKにも同じ問題があり、アップロードを制限することを提案していますが、AFNetworking
またはでそれを行う方法が見つかりませんでしたNSUrlConnection
。
また、iOSではストリーミング時に5分あたり5メガバイトの制限があることも覚えています。これが当てはまるかどうかはわかりませんが、3gの速度で、1分以内に約2メガをアップロードしています。多分それかもしれませんか?繰り返しますが、これに関連する情報は見つかりませんでした。
何か案は?これが私のコードです:
マルチパートアップロード:
NSMutableURLRequest *request = [[DIOSSession sharedSession] multipartFormRequestWithMethod:@"POST" path:[NSString stringWithFormat:@"%@/%@", kDiosEndpoint, @"demotix_services_story/upload"] parameters:params constructingBodyWithBlock: ^(id <AFMultipartFormData> formData) {
for (NSString * fkey in files) {
NSDictionary *file = [files objectForKey:fkey];
NSURL *fileUrl = [NSURL fileURLWithPath:[file valueForKey:@"fileUrl"]];
NSString *fileName = [file valueForKey:@"name"];
[formData appendPartWithFileURL:fileUrl name:fileName error:&error];
}
}];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
[operation setUploadProgressBlock:^(NSInteger bytesWritten, long long totalBytesWritten, long long totalBytesExpectedToWrite) {
[delegate updateUploadProgress:totalBytesWritten from:totalBytesExpectedToWrite];
}];
[operation setCompletionBlockWithSuccess:success failure:failure];
[operation start];
すべてのファイルを1つにまとめて、ストリーミングしてみてください。
NSURLRequest *nrequest = [[DIOSSession sharedSession] requestWithMethod:@"POST" path:[NSString stringWithFormat:@"%@/%@", kDiosEndpoint, @"demotix_services_story/upload"] parameters:params];
AFHTTPRequestOperation *noperation = [[AFHTTPRequestOperation alloc] initWithRequest:nrequest];
noperation.inputStream = [NSInputStream inputStreamWithFileAtPath:storePath];
noperation.outputStream = [NSOutputStream outputStreamToMemory];
[noperation setUploadProgressBlock:^(NSInteger bytesWritten, long long totalBytesWritten, long long totalBytesExpectedToWrite) {
[delegate updateUploadProgress:totalBytesWritten from:totalBytesExpectedToWrite];
}];
[noperation setCompletionBlockWithSuccess:success failure:failure];
[noperation start];
ありがとう、
アンドゥ