I’m downloading mp3 files from Rackspace cloud files, and for large files i’m encountering an issue where the download is completed successfully but the file is not yet downloaded completely. For example, a 40 MB mp3 file (01:00:00 duration) is download as as 4.5 MB mp3 file (00:10:30 duration). This doesn’t happen all the time.
- Any pointers as to what’s going on?
- Why is this happening, and how can i fix this issue?
- How can i build a simple checksum logic to check if the file was downloaded completely?
Here’s how i create and send an async request:
ASIHTTPRequest *request;
request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:urlString]];
[request setShouldAttemptPersistentConnection:NO];
[request setAllowResumeForFileDownloads:YES];
[request setDownloadProgressDelegate:self];
[request setShouldContinueWhenAppEntersBackground:YES];
[request setUserInfo:userInfo];
[request setDownloadDestinationPath:downloadPath];
[request setTemporaryFileDownloadPath:[NSString stringWithFormat:@"%@.download", downloadPath]];
[self.networkQueue addOperation:request];
[self.networkQueue go];
Note i’m using a network queue with 4 concurrent downloads.
Thanks.
Edit (Mon March 5, 2012, 03:25 PM)
So, further investigation shows that ASINetworkQueue is calling requestDidFinishSelector delegate method instead of requestDidFailSelector. The status code returned by the ASIHTTPRequest object is 206, HTTP/1.1 206 Partial Content in requestDidFinishSelector method. The status code should be 200, HTTP/1.1 200 OK.
I still don’t know why! and i still don’t know how to fix this. It seems that i’ll have to delete the partially downloaded file and start the download process again. At this point the temporary file i.e. %@.download is removed, and this partially downloaded file is put at the destination path.
So, this is what i ended up doing, and hopefully this’ll be enough (to solve the problem).
Here’s how i’m creating the network queue:
And here’s what my
contentRequestDidSucceed:method does:If there’s a better way to handle this, please let me know.