【问题标题】:Bulk Video Upload with AFNetworking使用 AFNetworking 批量上传视频
【发布时间】:2014-03-19 07:33:28
【问题描述】:

我正在尝试让 AFNetworking (1.x) 将一些长视频批量上传到我的服务器,但是当我使用标准功能时,应用程序的内存会飙升至 400MB,然后退出。

NSMutableArray *requests = [[NSMutableArray alloc] init];

NSMutableURLRequest *request = [[MyServerClient sharedClient] multipartFormRequestWithMethod:@"POST" path:URL parameters:@{ @"json": jsonString } constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
                [formData appendPartWithFileData:mediaData name:idString fileName:fileName mimeType:mimeType];
            }];

[request setTimeoutInterval:10800];

[requests addObject:operation];


[[MYServerClient sharedClient] enqueueBatchOfHTTPRequestOperationsWithRequests:requests   progressBlock:^(NSUInteger numberOfCompletedOperations, NSUInteger totalNumberOfOperations) {

        NSLog(@"Number - %d %d", numberOfCompletedOperations, totalNumberOfOperations);

    } completionBlock:^(NSArray *operations) {
        NSLog(@"Completion block");
    }];

MyServerClient 是 AFHTTPClient 的一个非常标准的子类:

- (id)initWithBaseURL:(NSURL *)url {
    self = [super initWithBaseURL:url];

    [self.operationQueue setMaxConcurrentOperationCount:1];

    [self registerHTTPOperationClass:[AFJSONRequestOperation class]];

    return self;
}

我猜测内存崩溃可能与应用程序未能限制并发操作量有关,但鉴于设置 setMaxConcurrentOperationCount,我不确定。有谁知道为什么会发生这种情况?

编辑:我的猜测是崩溃是由于应用程序在将媒体附加到多部分请求之前尝试将媒体加载到内存中。在这种 POST 使用场景中,是否有某种方法可以从磁盘流式传输上传?

【问题讨论】:

  • 分块发送视频..
  • @Rajneesh071 我计划在将来添加此方法,但是将它们全部上传应该不会导致上述行为,不是吗?

标签: ios networking post upload afnetworking


【解决方案1】:

对于遇到相同问题的任何人,以下似乎可以解决我的崩溃问题:

NSMutableURLRequest *request = [[MyServerClient sharedClient] multipartFormRequestWithMethod:@"POST" path:URL parameters:@{ @"json": jsonString } constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
                [formData appendPartWithFileURL:mediaURL name:idString error:nil];
            }];

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-04-29
    • 2016-01-21
    • 1970-01-01
    • 1970-01-01
    • 2017-02-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多