我尝试使用以下代码下载大约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];
答案 0 :(得分:1)
管理以解决问题。我动态创建的文件路径似乎丢失了,因此库无法保存文件。