McOffsky McOffsky - 6 months ago 13
HTML Question

Cordova android input file: cannot access some directories on device

My app, based on Cordova, allows users to upload images and PDF files to server.
I'm using a simple

<input type="file">
with the Dropzone.js plugin for layout and transport. It works fine for both iOS and Android. After clicking a button the file manager starts, you can choose file and it gets uploaded.

The problem is, on Android the user cannot choose files from directories in the upper part of the file selector. I have an LG G4, so I cannot choose from Last files, Google Drive, Images, Downloaded, Internal memory. I can choose from Gallery, Photos and File manager without any problem, but not any directory above the line.

I have permissions to read external storage. What am I missing here?

Here's screen from the tester:
Screen form the tester

Dropzone html, its as basic as it gets. Dropzone does not add here input type=file, but, much like jQuery, does it on the fly when file is selected.

<form action="file-upload" class="dropzone dropzone-form dz-clickable" rem="dropform" id="dropzone-form">
<input type="hidden" name="userId" value.bind="user_id" class="au-target" au-target-id="164">
<div class="text-center add_btn_wrapper">
<a class="btn btn-default btn-md dz-clickable" rem="dropbutton">Select file</a>
</div>
<div class="dz-default dz-message">
<span>Upload your scans</span>
</div>
</form>


Dropzone js declaration (I'm using Aurelia.js (es5/6) as frontend framework):

this.zone = new Dropzone(
_this.element.querySelector("[rem='dropform']"), {
url: this.auth.config.baseUrl + "../_uploader/file/upload",
maxFiles: this.max_files,
acceptedFiles: this.accepted_files,
clickable: [_this.element.querySelector("[rem='dropbutton']"), _this.element.querySelector("[rem='dropform']")],
dictDefaultMessage: this.label,
addRemoveLinks: this.allow_remove,
removedfile: (file) => { .... },
init: function() {
this.on("addedfile", (fx) => { .... });
this.on("complete", (fx) => { .... });
}
});


And in AndroidManifest.xml:

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.RECORD_AUDIO"/>
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="android.permission.MANAGE_DOCUMENTS"/>

Answer

Ok, the problem was caused by acceptedFiles parameter. For desktop I had there "image/*,.pdf" and it worked, but cordova with this value got confused and limited my access. For mobile I'm using now just "image/*", and it works as it should.

Comments