1

I'm building a mobile application with Cordova and Materialize. I'm trying to make the user select multiple files by using a file-field. It works well while trying on a PC browser, but on Android, I can never select more than one file. I tried to do the following lines, but none of them work:

<input type="file" multiple/>
<input type="file" multiple=""/>
<input type="file" multiple="multiple"/>

Is there a way to make that work with Android? I also tried the answer from this question but it popped several errors regarding missing symbols.

Okami
  • 11
  • 3

1 Answers1

0

An input element with type file does not work in cordova.

You will need to use a plugin that can assist you in accessing the file system.

Here is a function that I use in my apps: I use cordova-ourcodeworld-filebrowser

var multiple = options.multiple;
var startupPath = options.startupPath;
var callback = options.callback;

if (multiple != false) {
    multiple = true;
}

if (!window.OurCodeWorld) {
    throw "Git cordova plugin \"https://github.com/ourcodeworld/cordova-ourcodeworld-filebrowser.git\" required";
}

window.OurCodeWorld.Filebrowser.filePicker[multiple ? "multi" : "single"]({
    success: function (data) {
        if (!data.length) {
            alert("No file was selected");
            return;
        }

        if (typeof callback === "function") {
            callback(data);
        }

        return data;
    },
    error: function (err) {
        console.log(err);
    },
    startupPath: startupPath
});
Marius
  • 1,420
  • 1
  • 11
  • 19