Note that there are some explanatory texts on larger screens.

plurals
  1. POChecking filesize after download completed IOS4.3+
    primarykey
    data
    text
    <p>I'm trying to check the filesize of a document is correct after I download it to my documents directory. I'm not sure where to check it in my webservice helper file? Or the best method.</p> <p>I'm able to get the expected file length before it starts downloading. And I can get the length of data sent each burst. I was thinking to add these burst numbers up each time in didReceiveData then compare to the expected length but not sure how to add it up correctly.</p> <pre><code>- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response { filesize1 = [[NSNumber numberWithLong: [response expectedContentLength]] retain]; NSLog(@"%@", filesize1); if(requestType == DF_WS_REQUEST_GET_PDF_DATA) { [[NSFileManager defaultManager] createFileAtPath:self.filename contents:nil attributes:nil]; self.file = [[NSFileHandle fileHandleForUpdatingAtPath:self.filename] retain];// file is in .h if (self.file) { [self.file seekToEndOfFile]; } } else { [webData setLength: 0]; } } - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data { resourceLength = [NSNumber numberWithUnsignedInteger:[data length]]; NSLog(@"resource length: %d", [resourceLength intValue]); if(requestType == DF_WS_REQUEST_GET_PDF_DATA) { if (self.file) { [self.file seekToEndOfFile]; } [self.file writeData:data]; } else [webData appendData: data]; } - (void)connectionDidFinishingLoading:(NSURLConnection *)connection { URL = filePreviewViewController.filePath; NSError *AttributesError = nil; NSDictionary *FileAttributes = [[NSFileManager defaultManager] attributesOfItemAtPath:URL error:&amp;AttributesError]; NSNumber *FileSizeNumber = [FileAttributes objectForKey:NSFileSize]; long FileSize = [FileSizeNumber longValue]; NSLog(@"File: %@, Size: %ld", URL, FileSize); } </code></pre> <p>Any help or ideas would be appreciated greatly. Thanks.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload