App crases due to out of memory exception happening in java heap memory

Due to the introduction of scoped storage in Android 11, I’m unable to get the file information of document which user have selected using file picker plugin. Because now the file picker plugin is only providing content uri from which I’m unable to read the document.

In-order to get the actual file data, I’m copying the document content using content uri to my application this.file.dataDirectory location and reading the file.

Issue is when i try to copy a large file / video (>100mb) or reading large file makes the application crash. This is differing based on device RAM and storage space. Issue is happening when heap memory exceeds.

Issue1: I want to save and read huge document without crashing and also I want to send huge base64 string content of large document as a multipart data as API payload in which the application is crashing again.

Issue2: Previewing video document creates blob:http://localhost/08ab4d34-060c-4858-aa76-7ff954aee208 link, this src is failing with n/w status unknow throwing ERR:OUT_OF_MEMORY error.

@mhartington : Is my implementation right ?

Note: this memory crashing issue is happening only in android in iOS its working fine. I know the working of WKWebView is different than UIWebView is there any alternative approach available to overcome this issue.