Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
436 views
in Technique[技术] by (71.8m points)

android - cordova inappbrowser and input file

I have a iOS and Android application, and I load a external website inside my app (this external website is mine too). My problem is that this website has a file upload feature and this feature does not work on Android (it works on iOS). I saw that this behavior is normal on Android, but is there any way to make it work or it's definitely not an option ? Thank you

EDIT 1

I tried to create a new app with a simple page like this (hosted on AWS) :

<html>
<head>
    <title>Upload Test !</title>
</head>
<body>
    <div>Upload Test</div>
    <div>
        <input type="file" id="imgFile" name="files[]" accept="image/x-png, image/gif, image/jpeg">
    </div>      
</body>

and I added this script in my generated index.html in my Cordova project.

    <script type="text/javascript">
        document.addEventListener("deviceready", function(event) {
            console.log('TEST CONSOLE LOG !');
            var url = 'https://s3-eu-west-1.amazonaws.com/***/file-upload.html';
            ref = window.open(url, "_blank", "location=no,toolbar=no,zoom=no,hidden=yes");

            ref.addEventListener('loadstop', function () {
              ref.show();
            });
            ref.addEventListener('loaderror', function () {
              ref.close();
              ref = undefined;
            });
        }, false);
    </script>

It doesn't work on my nexus 5 (android M).

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

There's an issue with both Android and iOS that prevents file uploads when clicking on a file input tag like this within the inappbrowser:

<input type="file">

There's a couple of fixes for both which I've consolidated into a single location to make it easy for anyone else facing this issue. You should be able to modify your config.xml file to use it by including this:

<plugin spec="https://github.com/jverlee/cordova-plugin-inappbrowser-camera.git" version="1.1.0" source="git" />

Instead of the default inappbrowser plugin.

More details can be found here: https://github.com/jverlee/cordova-plugin-inappbrowser-camera


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...