-
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
Fixed and added support for dataUri in form data #33548
Conversation
Base commit: cf55fd5 |
Base commit: cf55fd5 |
@kelset @cortinico @lunaleaps can you please review this pr? |
Bitmap bitMap = BitmapFactory.decodeByteArray(decodedDataUrString, 0, decodedDataUrString.length); | ||
ByteArrayOutputStream bytes = new ByteArrayOutputStream(); | ||
bitMap.compress(Bitmap.CompressFormat.JPEG, 100, bytes); | ||
String path = MediaStore.Images.Media.insertImage(context.getContentResolver(), bitMap, "Title", null); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried to look up for more options, and datauri seems not supported out of the box. I agree to create a temp file and use the input stream like so is the correct solution. However, I suggest:
- Evaluate any impact on large image files
- Checkout the next method in this file, getDownloadFileInputStream, where it also created a temp file and return the inputstream. Can we somehow re-use the implementationt here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ryancat Thanks for the review! I've now converted the dataUri to bitmap and then attached an inputStream to the compressed bitmap. This way we won't have to store the image temporarily. I think converting the dataUri to Bitmap is necessary as there is no method that lets us convert the dataUri to inputStream directly. And regarding large size images, converting them to bitmap is the only(efficient) step I can think of, as the conversion is handled by in-built java function.
@ryancat The test which is failing, is related to my code changes? As I've made no changes in ios files. |
@cortinico Can you please review!? |
Bitmap bitMap = BitmapFactory.decodeByteArray(decodedDataUrString, 0, decodedDataUrString.length); | ||
ByteArrayOutputStream bytes = new ByteArrayOutputStream(); | ||
bitMap.compress(Bitmap.CompressFormat.JPEG, 100, bytes); | ||
ByteArrayOutputStream baos = new ByteArrayOutputStream(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this unused?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cortinico yes that variable is unused and i forgot to remove that before commiting.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cortinico I'm really sorry for inconvenience but i was trying to push my code changes but i messed up and ended up closing this PR(which tried to re-open but I cant, maybe maintainer can reopen)🤦😕. So I've opened a new PR for the same . I need to work on my GitHub skills
Summary: Continuation of #33548 Fixes #25790. The issue resulted because the [getFileInputStream() method of RequestBodyUtil failed to return an inputStream of the given dataUri ](https://github.com/facebook/react-native/blob/16397e0d3c0dd3374ddb642599725ca41f092a8a/ReactAndroid/src/main/java/com/facebook/react/modules/network/NetworkingModule.java#L427) This happened because the openInputStream() method of [context.getContentResolver() expects a content or a file](https://developer.android.com/reference/android/content/ContentResolver#openInputStream(android.net.Uri)) in its parameter but instead received dataUri which resulted in FileNotFoundException. ![issue](https://user-images.githubusercontent.com/38756320/161345967-fd79d3e2-54a8-4a0e-8a6b-189ce9883a78.jpeg) **Solution**: I've now converted the dataUri to bitmap and then attached an inputStream to the compressed bitmap. This way we won't have to store the image temporarily. I think converting the dataUri to Bitmap is necessary as there is no method that lets us convert the dataUri to inputStream directly. And regarding large size images, converting them to bitmap is the only(efficient) step I can think of, as the conversion is handled by in-built java function. This issue has been unresolved for quite some time now, so resolving this PR would be greatly appreciated. ## 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] [Added] - Support for dataUri in form data Pull Request resolved: #33675 Reviewed By: christophpurrer, mdvacca Differential Revision: D36205586 Pulled By: cortinico fbshipit-source-id: bfc83efcec0b2fcb1df42e4bf1d43c966de8f40e
Summary
Fixes #25790. The issue resulted because the getFileInputStream() method of RequestBodyUtil failed to return an inputStream of the given dataUri This happened because the openInputStream() method of context.getContentResolver() expects a content or a file in its parameter but instead received dataUri which resulted in FileNotFoundException.
. Therefore it makes sense to provide a file path to the openInputStream method instead of dataUri.
Solution:
This issue has been unresolved for quite some time now, so resolving this PR would be greatly appreciated.
Changelog
[Android] [Added] - Support for dataUri in form data
Test Plan