-
Notifications
You must be signed in to change notification settings - Fork 24.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Image does not load on Android when blob is bigger than 64kB #31774
Comments
When loading the image, react-native/ReactAndroid/src/main/java/com/facebook/react/modules/blob/BlobProvider.java Lines 57 to 96 in dc80b2d
The issue may be related to the fact that pipe capacity is 65536 bytes and the write operation is blocking or it performs only a partial write if there is more bytes to be written (https://man7.org/linux/man-pages/man7/pipe.7.html, sections "Pipe capacity" and "PIPE_BUF"). |
Summary: Fixes #31774. This pull request resolves a problem related to accessing blobs greater than 64 KB on Android. When an object URL for such blob is passed as source of `<Image />` component, the image does not load. This issue was related to the fact that pipe buffer has a limited capacity of 65536 bytes (https://man7.org/linux/man-pages/man7/pipe.7.html, section "Pipe capacity"). If there is more bytes to be written than free space in the buffer left, the write operation blocks and waits until the content is read from the pipe. The current implementation of `BlobProvider.openFile` first creates a pipe, then writes the blob data to the pipe and finally returns the read side descriptor of the pipe. For blobs larger than 64 KB, the write operation will block forever, because there are no readers to empty the buffer. https://github.com/facebook/react-native/blob/41ecccefcf16ac8bcf858dd955af709eb20f7e4a/ReactAndroid/src/main/java/com/facebook/react/modules/blob/BlobProvider.java#L86-L95 This pull request moves the write operation to a separate thread. The read side descriptor is returned immediately so that both writer and reader can work simultaneously. Reading from the pipe empties the buffer and allows the next chunks to be written. ## Changelog <!-- Help reviewers and the release process by writing your own changelog entry. For an example, see: https://github.com/facebook/react-native/wiki/Changelog --> [Android] [Fixed] - Fix support for blobs larger than 64 KB Pull Request resolved: #31789 Test Plan: A new example has been added to RN Tester app to verify if the new implementation properly loads the image of size 455 KB from a blob via object URL passed as image source. <img src="https://user-images.githubusercontent.com/20516055/123859163-9eba6d80-d924-11eb-8a09-2b1f353bb968.png" alt="Screenshot_1624996413" width="300" /> Reviewed By: ShikaSD Differential Revision: D29674273 Pulled By: yungsters fbshipit-source-id: e0ac3ec0a23690b05ab843061803f95f7666c0db
Description
When an object URL for a blob of size greater than 64 kB is passed as source of
<Image />
component, the image does not load on Android (but it works fine on iOS).video.mp4
React Native version:
Steps To Reproduce
BlobProvider
as a Content Provider according to the following instructions:react-native/Libraries/Blob/URL.js
Lines 27 to 50 in 33ef82c
URL.createObjectURL
:<Image />
component.Expected Results
It should work for blobs bigger than 64 kB on Android as well.
Snack, code example, screenshot, or link to a repository:
https://github.com/tomekzaw/blobissue
The text was updated successfully, but these errors were encountered: