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