1

我尝试使用以下代码下载大约 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];
4

1 回答 1

1

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

于 2012-12-18T06:35:38.967 回答