I'm using downloadTaskWithRequest
to download some files and I'm using KVO to observe progression.
Here is my code :
// create the request from an url
NSMutableURLRequest *request = [mySession.requestSerializer requestWithMethod:@"GET" URLString:url parameters:nil error:&serializationError];
NSProgress *localProgress = nil;
NSURLSessionDownloadTask *downloadTask = [mySession downloadTaskWithRequest:request
progress:localProgress
destination:^NSURL *(NSURL *targetPath, NSURLResponse *response)
{ ... }
completionHandler:^(NSURLResponse *response, NSURL *filePath, NSError *error)
{ ... }];
Downloading the file works perfectly, but why in some case I can follow the progression, and for others the progress is never updated ?
url with progression ok :
url = @"http://www.fond-ecran-hd.net/pc-driver/1351.jpg";
url with no progression :
url = @"http://lorempixel.com/1920/1920/";
I'm aware that the difference beetween working and not working cases is that some url are straight link to the file (/path/file.ext) and not the others. But I would like to know why, and if there is a workaround...
The HTTP Response object that I get from the URL must contains a header called Content-Length which will give the length of the file !
If the server doesn't return this, it seems to be impossible to track download progression.