In the DidPickDocument
event of UIDocumentPickerViewController
I try to import/write the selected file into the app's local Documents directory.
This works fine with "small" files (e.g < 100MB) using a subclassed UIDocument class with overriden
public override bool LoadFromContents(NSObject contents, string typeName, out NSError outError)
{
outError = null;
if (contents != null)
{
Content = ((NSData)contents).ToArray();
}
...
...and by calling
MySubclassedDoc mySubclassedDoc = new MySubclassedDoc (nsurl);
bool success = await mySubclassedDoc.OpenAsync();
File.WriteAllBytes("targetFile.xyz", mySubclassedDoc.Content);
But if the file is larger (eg. 400MB) the app crashes before LoadFromContents
is called because of insufficent memory (RAM).
So there need to be a way to stream the selected file directly to a file. How can you do this using the given NSUrl ?