expo / expo/react-native-blob-test
Blob support causes OOM on Android with large files
- Dominant language
- JavaScript
- Stars
- 5
- Forks
- 2
- PR merge metrics
- No merged PRs in 30d
Description
@satya164 Created this issue to ask your advise regarding an OutOfMemory Error with the RN Blob support.
Following the test code in this repo. I'm attempting to create a blob from a file url. (A 400 MB HD video)
```
const response = await fetch(uri);
const blob = await response.blob();
```
While it works on iOS. On Android the fetch fails.
```
Failed to send url request: file:////data/user/0/com.package.name/cache/rn_image_picker_lib_temp_b4276c3a-82e8-4be7-b2a9-be1470358ae7.mp4
java.lang.OutOfMemoryError: Failed to allocate a 33554448 byte allocation with 19742688 free bytes and 18MB until OOM, target footprint 536870912, growth limit 536870912
at java.util.Arrays.copyOf(Arrays.java:3585)
at java.io.ByteArrayOutputStream.grow(ByteArrayOutputStream.java:120)
at java.io.ByteArrayOutputStream.ensureCapacity(ByteArrayOutputStream.java:95)
at java.io.ByteArrayOutputStream.write(ByteArrayOutputStream.java:156)
at com.facebook.react.modules.blob.BlobModule.getBytesFromUri(BlobModule.java:231)
at com.facebook.react.modules.blob.BlobModule.-$$Nest$mgetBytesFromUri(Unknown Source:0)
at com.facebook.react.modules.blob.BlobModule$2.fetch(BlobModule.java:83)
at com.facebook.react.modules.network.NetworkingModule.sendRequestInternal(NetworkingModule.java:278)
at com.facebook.react.modules.network.NetworkingModule.sendRequest(NetworkingModule.java:241)
at java.lang.reflect.Method.invoke(Native Method)
```
I have android:largeHeap="true" set in the Manifest and it works fine with smaller files.
Do you think this can be handled differently, i.e. not read the whole file into memory ? I'm happy to work on it if you have suggestions for better handling in either the BlobModule or js side.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.