2012-12-18 169 views
1

我試圖下載100 MB左右的文件,使用下面的代碼。我的下載進度塊成功顯示了讀取和預期的字節數量,但文件似乎不存在於文件系統中。AFNetworking無法下載文件

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

http://stackoverflow.com/questions/12003335/afnetworking-fails-to-download-large-files?rq=1 –

回答

1

管理解決問題。我動態創建的文件路徑似乎缺失,因此庫無法保存文件。