AFNetworking无法下载文件

时间:2012-12-18 05:38:27

标签: iphone ios afnetworking

我尝试使用以下代码下载大约100 MB的文件。我的下载进度块成功显示了读取和预期的字节数,但文件似乎不存在于文件系统中。

 NSMutableURLRequest *request = [self.httpClient requestWithMethod:REQUEST_GET
                                                             path:@"" parameters:params];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setTimeoutInterval:15];

AFURLConnectionOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
operation.outputStream = [NSOutputStream outputStreamToFileAtPath:filePath append:NO];

[operation setDownloadProgressBlock:^(NSUInteger bytesRead, long long totalBytesRead, long long totalBytesExpectedToRead) {
    NordecaLog("read %d, total %lld, expected %lld ->", bytesRead , totalBytesRead, totalBytesExpectedToRead);
    [self.delegate updateProgressWithBytesRead:totalBytesRead totalBytesExpected:totalBytesExpectedToRead];
}];
[operation setCompletionBlock:^{
    NSHTTPURLResponse* httpResponse = (NSHTTPURLResponse*)operation.response;
    int responseStatusCode = [httpResponse statusCode];
    NSString *md5CheckSum = [[httpResponse allHeaderFields]  objectForKey:@"MD5Checksum"];

    NordecaLog("MD 5 %@ ->", md5CheckSum);

    block(md5CheckSum, responseStatusCode, nil);
    NordecaLog("Success %i ->", responseStatusCode);
}];


[operation start];

1 个答案:

答案 0 :(得分:1)

管理以解决问题。我动态创建的文件路径似乎丢失了,因此库无法保存文件。