-
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
Avoid re-encoding images when uploading local files #31457
Closed
arthuralee
wants to merge
2
commits into
facebook:master
from
arthuralee:improve-local-image-loading
Closed
Avoid re-encoding images when uploading local files #31457
arthuralee
wants to merge
2
commits into
facebook:master
from
arthuralee:improve-local-image-loading
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
facebook-github-bot
added
the
CLA Signed
This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
label
Apr 30, 2021
Base commit: 9e020ef |
Base commit: 9e020ef |
This was referenced May 11, 2021
@yungsters has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator. |
@PeteTheHeat merged this pull request in f78526c. |
facebook-github-bot
pushed a commit
that referenced
this pull request
Jun 16, 2021
Summary: In D28630805 (f78526c) ([github link](#31457)) I added a setter to workaround a bug I perceived with `moduleRegistry`. Turns out - the proper fix was to remove the `synthesize` line. See conversation on linked diff for more context. Changelog: [Internal] Reviewed By: RSNara Differential Revision: D29144717 fbshipit-source-id: aa95b670b540b9007eed76769c9babc10ea399ce
facebook-github-bot
pushed a commit
that referenced
this pull request
Dec 12, 2024
Summary: # Summary I'm working to get the main `react-native` package parsable by modern Flow tooling (both `flow-bundler`, `flow-api-translator`). This diff trivially removes some redundant Flow comment syntax in `ReactNativeTypes.js`, which fixes parsing under these newer tools. ## How did you test this change? Files were pasted into `react-native-github` under fbsource, where Flow validates ✅. DiffTrain build for [92b62f500c3fca44a9dc9ead936ef3bf19481f02](facebook/react@92b62f5) Reviewed By: huntie Differential Revision: D67100354 Pulled By: hoxyq fbshipit-source-id: 575e4bd8ceefad15576273920a263ae89d027cad
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
CLA Signed
This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
Merged
This PR has been merged.
Needs: React Native Team Attention
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #27099
When you upload a local file using XHR + the
FormData
API, RN usesRCTNetworkTask
to retrieve the image file data from the local filesystem (request URL is a file:// URL) (code pointer). As a result, if you are uploading a local image file that is in the app's directoryRCTNetworkTask
will end up usingRCTLocalAssetImageLoader
to load the image, which reads the image into aUIImage
and then re-encodes it usingUIImageJPEGRepresentation
with a compression quality of 1.0, which is the higest (code pointer). Not only is this unnecessary, it ends up inflating the size of the jpg if it had been previously compressed to a lower quality.With this PR, this issue is fixed by forcing the
RCTFileRequestHandler
to be used when retrieving local files for upload, regardless of whether they are images or not. As a result, any file to be uploaded gets read intoNSData
which is the format needed when appending to the multipart body.I considered fixing this by modifying the behavior of how the handlers were chosen, but this felt like a safer fix since it will be scoped to just uploads and wont affect image fetching.
Changelog
[iOS] [Fixed] - Avoid re-encoding images when uploading local files
Test Plan
The repro for this is a bit troublesome, especially because this issue doesn't repro in RNTester. There is some code that is to be overriding the handlers that will be used, excluding the
RCTImageLoader
. I had to repro this in a fresh new RN app.Original file:
Uploaded file (with and without patch):
Would appreciate pointers on whether this needs to be tested more extensively