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
Fix #33 Support Android file upload #60
Fix #33 Support Android file upload #60
Conversation
- supports photo and video capture - supports the accept attribute - supports the multiple attribute
Thank you for the fast work 🚀 ! I've linked your PR to a few people to get more reviews so we can get this right |
I'm out of town until this weekend and won't have time until then -- but will take a look when I can! |
So about the FileProvider, it's great I think as it is the recommended way to do that by Google. I'm not an android expert to judge the rest, but it seems fine to me. One thing tho: I know that the code you used is only working on Android 5 or more, that is fine to me, as supporting older versions means using unofficial/undocumented APIs, but we should document that. |
@lucasferreira Can you look at this ? |
Hi @Titozzz, I my soft experience when I implemented the same support in react-native-android-webview it's that you never could "cover" all the Android devices around there. This could be something to warn in a future documentation about this file uploading feature. But I will try to look and help with the @andreipfeiffer good work ;) |
@Titozzz It's true that I haven't tested on versions older than 5, but from my best guess, it should work (or more precisely, we could implement support), maybe with fewer features. Currently, there's a |
In regard to the |
@@ -413,6 +414,10 @@ public boolean onConsoleMessage(ConsoleMessage message) { | |||
public void onGeolocationPermissionsShowPrompt(String origin, GeolocationPermissions.Callback callback) { | |||
callback.invoke(origin, true, false); | |||
} | |||
|
|||
public boolean onShowFileChooser(WebView webView, ValueCallback<Uri[]> filePathCallback, FileChooserParams fileChooserParams) { |
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.
This does not gets triggered below 5.0 (not only because of the @targetAPI but also cause this was implemented in 5.0)
There are others function signature that allow unofficial support but I'm not sure there is a point to support this below 5.0
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.
4.1-4.4 (SDK 16-19) which means JellyBean & KitKat cover more than 10% of market share.
If it's easy to cover that, I think it's definitely worth it.
I would like to give it a shot, at least.
If we were to support that feature only on 5.0+ devices that would be fine to me. We need to verify however that we can still use the webview as before on older devices |
@Titozzz I could take a look on how to support 4.1+. Since RN sets The only question is that if you think I should tackle this on this PR, or not. |
The worst thing about 4.1+ old API it's that we can't have support for multifile html5 inputs. And @andreipfeiffer it's right, RN |
You could make it work for 4.1-4.3 but never for 4.4, and that would mean using undoc APIs so I'm not that hyped about it. We are trying to keep that repo as clean as possible even if it is PRE-release as it is already linked by the 0.57 changelog and some people already use it |
So we can point that this feature will work only in Android 5+ and we could provide some method to check file input upload support? Something like With that the developers could test if the android version supports or not the file upload feature and warn (or adapt) his webview use to that. What do you guys think? |
That is interesting @lucasferreira |
@lucasferreira I would support that. |
I would implement basic file upload (without multiple) for sdk 16+ and progressively enhance it with supported features: Android 4.1-4.4 (SDK 16-19) which means JellyBean & KitKat, cover more than 10% of market share. I'll try to do that these days. |
@andreipfeiffer I really believe there is no way to get 4.4 to work and without this 4.1 to 4.3 has a really low market share. I'd go with 5+ only and @lucasferreira suggestion. However if you guys prefer the other way that's fine by me but we need to document the compatibility features for <5 so that once react-native drops support for Android < 5 migration is easy |
I'm fine with either approach. @Titozzz @lucasferreira My knowledge is kinda limited, so could you please explain why is it not possible to implement a basic file upload for 4.4? |
Woaw, didn't know about that. Thanks for the insight @Titozzz
|
I would not bother and just check the version. |
I agree with you guys @Titozzz and @andreipfeiffer. Good method name |
Will look into it in the following days. |
On iOS it would just return |
Really appreciate your work on this, @andreipfeiffer !!! ❤️ |
@jamonholmgren @Titozzz I agree that we should release this as is. |
android/src/main/java/com/reactnativecommunity/webview/RNCWebViewModule.java
Show resolved
Hide resolved
🎉 This PR is included in version 2.10.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
@allcontributors[bot] please add @andreipfeiffer for code, review, ideas |
I've put up a pull request to add @andreipfeiffer! 🎉 |
Not sure what it was like when first implemented in react-native-webview#60, but currently if user chooses multiple files to upload, only the first one will actually be uploaded. The reason behind this is that when mulitple files are selected, both `getData` and `getClipData` will not be null, but `getData` only contains the first of those selections. Reordering file selection logic to consider the multiple file case first.
Not sure what it was like when first implemented in react-native-webview#60, but currently if user chooses multiple files to upload, only the first one will actually be uploaded. The reason behind this is that when mulitple files are selected, both `getData` and `getClipData` will not be null, but `getData` only contains the first of those selections. Reordering file selection logic to consider the multiple file case first.
Not sure what it was like when first implemented in react-native-webview#60, but currently if user chooses multiple files to upload, only the first one will actually be uploaded. The reason behind this is that when mulitple files are selected, both `getData` and `getClipData` will not be null, but `getData` only contains the first of those selections. Reordering file selection logic to consider the multiple file case first. (cherry picked from commit 7920ccb)
Fixes react-native-webview#33 I could really use some help from an Android developer on this one, because I just "made it work", don't know how to "make it work good". Some things that should be reviewed: - [ ] validate Android 5.0 devices (my emulator work, but outputs some weird sounds; a Galaxy 4 I tested on crashes) - [ ] validate Android 5.1 devices (emulator works, couldn't find a real device) - [ ] how to handle File Extensions? (https://www.w3schools.com/tags/att_input_accept.asp) I'm sure that there's more refactoring to be done, so any help and advice would be appreciated.
# [2.10.0](react-native-webview/react-native-webview@v2.9.0...v2.10.0) (2018-11-21) ### Features * **Android:** Support Android file upload ([react-native-webview#60](react-native-webview#60)) ([752a5b2](react-native-webview@752a5b2)), closes [react-native-webview#33](react-native-webview#33)
Not sure what it was like when first implemented in react-native-webview#60, but currently if user chooses multiple files to upload, only the first one will actually be uploaded. The reason behind this is that when mulitple files are selected, both `getData` and `getClipData` will not be null, but `getData` only contains the first of those selections. Reordering file selection logic to consider the multiple file case first. (cherry picked from commit 7920ccb)
# [2.10.0](react-native-webview/react-native-webview@v2.9.0...v2.10.0) (2018-11-21) ### Features * **Android:** Support Android file upload ([#60](react-native-webview/react-native-webview#60)) ([752a5b2](react-native-webview/react-native-webview@752a5b2)), closes [#33](react-native-webview/react-native-webview#33)
Fixes #33
I could really use some help from an Android developer on this one, because I just "made it work", don't know how to "make it work good".
Some things that should be reviewed:
I'm sure that there's more refactoring to be done, so any help and advice would be appreciated.