how to find the size of a document in iCloud before picking it and downloading to device using UIDocumentPickerViewController.I can download the document to the device and then converting to NSData,i can determine the file size,but can we avoid downloading the document itself and predetermine the file size before downloading .I could not find any method or property in uidocumentpickerviewcontroller.
- (void)documentPicker:(UIDocumentPickerViewController *)controller didPickDocumentAtURL:(NSURL *)url {
NSFileCoordinator *coordinator = [[NSFileCoordinator alloc] initWithFilePresenter:nil];
NSError *error = nil;
[coordinator coordinateReadingItemAtURL:url options:0 error:&error byAccessor:^(NSURL *newURL) {
//assuming the file coordinator has downloaded the file here and provided the new url here
}
}
configure the file coordinator to just read the metadata only instead of downloading the entire file.From this url we get the filesize of a file in cloud using the method getPromisedItemResourceValue: forKey:NSURLFileSizeKey error:
Please post any answer that is more efficient than this way.This is the solution that worked for me
- (void)documentPicker:(UIDocumentPickerViewController *)controller didPickDocumentAtURL:(NSURL *)url {
NSError *error = nil;
NSFileCoordinator *coordinator = [[NSFileCoordinator alloc] initWithFilePresenter:nil];
[coordinator coordinateReadingItemAtURL:url options:NSFileCoordinatorReadingImmediatelyAvailableMetadataOnly error:&error byAccessor:^(NSURL *newURL) {
NSError *err = nil;
NSNumber * fileSize;
if(![url getPromisedItemResourceValue:&fileSize forKey:NSURLFileSizeKey error:&err]) {
NSLog(@"Failed error: %@", error);
return ;
} else {
NSLog(@"fileSize %f",fileSize.doubleValue);
}
}
}