Thangavel
Thangavel

Reputation: 216

Download folder using AFNetworking in ios

I would like to download a folder which consists several kind of files(png,jpg,mov,txt and pdf). I am using AFNetworking. I have used below code for downloading,

NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:[Utilities urlencode:imageURL]]];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
operation.outputStream = [NSOutputStream outputStreamToFileAtPath:str_path append:NO];

[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject)
{
    //NSLog(@"Successfully downloaded file to %@", str_path);
}
failure:^(AFHTTPRequestOperation *operation, NSError *error)
{
    NSLog(@"Error: %@ =====%@ =======%@", error.localizedDescription,str_path,imageURL);
}];

[operation setDownloadProgressBlock:^(NSUInteger bytesWritten, long long totalBytesWritten, long long totalBytesExpectedToRead)
{
    float progress = totalBytesWritten / (float)totalBytesExpectedToRead;
    NSLog(@"Download Percentage: %f %%", progress*100);
}];

[operation start];

The above code works fine for individual files. But i have got error code of 21 while downloading folder. Any help would be greatly appreciated.

Upvotes: 0

Views: 406

Answers (1)

Gus Hovland
Gus Hovland

Reputation: 91

HTTP does not support downloading multiple files in one request. This is pretty much the same question asked here in reverse.

If you have FTP access you can use the CFFTP API to download the contents of a directory.

Upvotes: 1

Related Questions