question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Missing Intent type and category prevent file upload - [solution included]

See original GitHub issue

Bug Report

Files upload not working on Android when the Cordova App uses ng-file-upload.

( works on iOS 👇👇 ) image

Problem

Using ng-file-upload it is not possible to upload images or document on Android when the App is built using Cordova.

The 2 lines fix suggested below will resolve the Issue opened here on the ng-file-upload repository and the related Stackoverflow.

This is the line after which the following 2 lines of code need to be added: https://github.com/apache/cordova-android/blob/2163c8ae0536bfde9029cfc981b945f4af93e09f/framework/src/org/apache/cordova/engine/SystemWebChromeClient.java#L253

Bug fix - 2 lines of code:

    @TargetApi(Build.VERSION_CODES.LOLLIPOP)
    @Override
    public boolean onShowFileChooser(WebView webView, final ValueCallback<Uri[]> filePathsCallback, final WebChromeClient.FileChooserParams fileChooserParams) {
        Intent intent = fileChooserParams.createIntent();
        // FIX HERE (same as the above handler) vvvvvvvvvvvvvv @@
        intent.addCategory(Intent.CATEGORY_OPENABLE); 
        intent.setType("*/*");
        // FIX HERE ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@

What is expected to happen?

The user should be prompted to choose which app to use to pick a file to upload

What does actually happen?

On click no file picker is shown

Information

These logs get generated when the upload button that should open the file picker is clicked:

“No activity found to handle file chooser intent.: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.GET_CONTENT cat= [android.intent.category.OPENABLE] typ=.jpg,.png,.tiff,.jpeg,.tif,.pdf }”

Command or Code

Unfortunately I cannot share the code.

Environment, Platform, Device

Android app built with Cordova.

Same result using the default WebView and the WebView provided by cordova-plugin-ionic-webview.

Version information

Same result on cordova-android 7 and 8.

Checklist

  • I searched for existing GitHub issues
  • I updated all Cordova tooling to most recent version
  • I included all the necessary information above

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:3
  • Comments:13 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
ksch10bobcommented, Jun 12, 2020

@breautek i can only speak for android Versions from 5.xx

case 1 : no or an empty accept attribute is specified. Works like intended, you get the fully featured file picker

case 2 : your specify an accept attribute on the input tag that contains at least 2 entries try <input type="file" accept="application/pdf, image/jpeg" /> in your minimal cordova repo

expected

you can choose jpegs and pdfs

actually

you can only choose pdfs

1reaction
breautekcommented, Jun 14, 2020

I didn’t try that specifically but for android omitting the accept attribute had the effect of allowing any file.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Allowing Other Apps to Start Your Activity - Android Developers
The methods startActivity() and startActivityForResult() treat all intents as if they declared the CATEGORY_DEFAULT category.
Read more >
File Upload - OWASP Cheat Sheet Series
Although it should not be relied upon for security, it provides a quick check to prevent users from unintentionally uploading files with the...
Read more >
App links intent filters in assetlinks.json not working on Android
Create assetlinks.json using Tools > App Links Assistant . Then press Open Digital Asset Links File Generator , enter domain, application id, select ......
Read more >
Upload MIME type restriction (instance security hardening)
Use the glide.security.file.mime_type.validation property to activate MIME type checking for uploads. You can enable (set the property to ...
Read more >
Insecure File Upload - Beagle Security
In many web servers, the vulnerability depends entirely on its purpose, allowing a remote attacker to upload a file with malicious content. This ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found