fix(android): Prevent out of memory errors on Android when selecting large media (video) files from the gallery picker.#923
Conversation
…large media (video) files from the gallery picker. Changes from apache#906 resulted in all gallery picker results being read in full into a byte array. This works fine when dealing with images, however when larger files (videos for example) are selected it will nearly always result in an out of memory error (reading too much data in one go). With videos no transformation is required, the URI simply need to be returned.
|
@breautek thanks for triggering the automated checks. Would you be able to kindly confirm that the failures on the automated checks are due to environment timeouts as opposed to this PRs code changes? I've looked through the logs. From what I can tell they seem to be failing due to either timeouts when trying to setup devices or not having a suitable runner (iOS). |
Don't worry about Chrome and iOS here. Chrome always fails for anything that requires user intervention (aka to accept browser permissions). iOS seems outdated, but your PR doesn't modify any shared code (e.g. JS) or iOS platform code, so you're good there. Android 7.1 test is also probably CI environmental. Specifically that one fails frequently for some reason, across all of our repos. It's likely not related to your PR. I've only taken a glance at the PR myself but tbh I think you're good there. |
Platforms affected
Android
Motivation and Context
Changes from #906 resulted in all gallery picker results being read in full into a byte array.
See this line.
Reading in the data fully into memory works generally fine when dealing with images.
When handling larger files (videos for example), it will nearly always result in an out of memory error (reading too much data in one go).
With videos no transformation is required, the URI simply need to be returned.
Steps to recreate issue:
camera.getPicturewithdestinationTypeasCamera.DestinationType.FILE_URImediaTypeasCamera.MediaType .VIDEOsourceTypeasCamera.PictureSourceType.PHOTOLIBRARYDescription
Re-ordered and cleaned up the code for
processResultFromGalleryto only read the file data when required.If its a video or MIME type which it cannot transform, then simply return the URI.
Similarly if the special case for just returning the path without scaling is met, avoid reading in any data.
Testing
No issues spotted. Images and videos were selected and saved into application storage without issue.
Checklist
(platform)if this change only applies to one platform (e.g.(android))