Skip to content
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

Merged
merged 38 commits into from Nov 21, 2018
Merged

Fix #33 Support Android file upload #60

merged 38 commits into from Nov 21, 2018

Conversation

andreipfeiffer
Copy link
Contributor

@andreipfeiffer andreipfeiffer commented Sep 25, 2018

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:

  • 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.

- supports photo and video capture
- supports the accept attribute
- supports the multiple attribute
@Titozzz
Copy link
Collaborator

Titozzz commented Sep 25, 2018

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

@jamonholmgren
Copy link
Member

I'm out of town until this weekend and won't have time until then -- but will take a look when I can!

@Titozzz
Copy link
Collaborator

Titozzz commented Sep 25, 2018

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.

@Titozzz
Copy link
Collaborator

Titozzz commented Sep 25, 2018

@lucasferreira Can you look at this ?

@lucasferreira
Copy link

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 ;)

@andreipfeiffer
Copy link
Contributor Author

@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 @TargetApi(Build.VERSION_CODES.LOLLIPOP) set on the createViewInstance() method in the RNCWebViewManager that was there previously, which is preventing the onShowFileChooser() also.

@andreipfeiffer
Copy link
Contributor Author

In regard to the FileProvider which was added in sdk 22, I have no idea what happens on sdk 21, which is LOLLIPOP 5.0. I'll have to check that.

@lucasferreira
Copy link

lucasferreira commented Sep 25, 2018

By the comments of @Titozzz Android 5+ could be a requirement to use that "featured"

But here we have a "sort of" implementation for Android 4.1+ without multifile support.

@@ -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) {
Copy link
Collaborator

@Titozzz Titozzz Sep 26, 2018

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

Copy link
Contributor Author

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.

@Titozzz
Copy link
Collaborator

Titozzz commented Sep 26, 2018

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

@andreipfeiffer
Copy link
Contributor Author

@Titozzz I could take a look on how to support 4.1+. Since RN sets minSdkVersion to 16 by default, I guess users would expect that for any community package as well.

The only question is that if you think I should tackle this on this PR, or not.
Since this is not production ready, I don't see an issue to merge this PR and add support for older SDKs later.

@lucasferreira
Copy link

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 minSdkVersion it's 16 and I really don't know if it good to support (or not) older Android versions bellow 5.0.

@Titozzz
Copy link
Collaborator

Titozzz commented Sep 26, 2018

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

@lucasferreira
Copy link

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 this.refs.myWebView.supportsFileUpload()?

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?

@Titozzz
Copy link
Collaborator

Titozzz commented Sep 26, 2018

That is interesting @lucasferreira

@jamonholmgren
Copy link
Member

@lucasferreira I would support that.

@andreipfeiffer
Copy link
Contributor Author

andreipfeiffer commented Sep 27, 2018

I would implement basic file upload (without multiple) for sdk 16+ and progressively enhance it with supported features: accept attr, multiple attr.

Android 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'll try to do that these days.

@Titozzz
Copy link
Collaborator

Titozzz commented Sep 27, 2018

@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

@andreipfeiffer
Copy link
Contributor Author

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?

@Titozzz
Copy link
Collaborator

Titozzz commented Sep 28, 2018

delight-im/Android-AdvancedWebView#4 (comment)

@andreipfeiffer
Copy link
Contributor Author

Woaw, didn't know about that. Thanks for the insight @Titozzz
In that case, I would support @lucasferreira 's proposal also, which 2 things to clarify:

  1. how should that method be implemented? by verifying the version? or is feature detection possible?
  2. how should we name the method? I would prefix it with something that suggests a boolean value, like isFileUploadSupported()

@Titozzz
Copy link
Collaborator

Titozzz commented Sep 28, 2018

I would not bother and just check the version.
I like prefixing bool values with is too.
Do not forget to add it on iOS too then

@lucasferreira
Copy link

I agree with you guys @Titozzz and @andreipfeiffer.

Good method name isFileUploadSupported and check SDK_VERSION for a simple comparison.

@andreipfeiffer
Copy link
Contributor Author

Will look into it in the following days.

@jamonholmgren
Copy link
Member

On iOS it would just return true, right?

@jamonholmgren
Copy link
Member

Really appreciate your work on this, @andreipfeiffer !!! ❤️

@andreipfeiffer
Copy link
Contributor Author

@jamonholmgren @Titozzz
I have updated the first comment of the PR.
My main 2 concerns are in regard to Android 5.0 & Android 5.1.

I agree that we should release this as is.
It's not perfect, but it's more than what's currently available.

@vitorreis
Copy link
Contributor

Me waiting for this merge

@Titozzz Titozzz merged commit 752a5b2 into react-native-webview:master Nov 21, 2018
Titozzz pushed a commit that referenced this pull request Nov 21, 2018
# [2.10.0](v2.9.0...v2.10.0) (2018-11-21)

### Features

* **Android:** Support Android file upload ([#60](#60)) ([752a5b2](752a5b2)), closes [#33](#33)
@Titozzz
Copy link
Collaborator

Titozzz commented Nov 21, 2018

🎉 This PR is included in version 2.10.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@Titozzz

This comment has been minimized.

@allcontributors

This comment has been minimized.

@Titozzz

This comment has been minimized.

@allcontributors

This comment has been minimized.

@Titozzz
Copy link
Collaborator

Titozzz commented Jan 18, 2019

@allcontributors[bot] please add @andreipfeiffer for code, review, ideas

@allcontributors
Copy link
Contributor

@Titozzz

I've put up a pull request to add @andreipfeiffer! 🎉

trcoffman pushed a commit to appfolio/react-native-webview that referenced this pull request Apr 8, 2020
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.
hojason117 added a commit to hojason117/react-native-webview that referenced this pull request Apr 21, 2020
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.
hojason117 added a commit to appfolio/react-native-webview that referenced this pull request Apr 23, 2020
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)
phuongwd pushed a commit to phuongwd/react-native-webview that referenced this pull request Apr 29, 2020
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.
phuongwd pushed a commit to phuongwd/react-native-webview that referenced this pull request Apr 29, 2020
hojason117 added a commit to appfolio/react-native-webview that referenced this pull request May 8, 2020
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)
noproblem23 added a commit to noproblem23/react-native-webview that referenced this pull request Apr 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Maintainer: ready to publish This PR has been reviewed and is ready to be published
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

10 participants