File Chooser issue, Selecting files from "Downloads" Folder

Greetings,

File Chooser plugin works fine, but in some situations it does not:

1- I can choose a file, but it does not get processed. This is due permission was not granted. Choosing a file does not prompt permission!?

*I had to request

*if I take a picture instead, permission prompted will show up. once permission granted, I can go back and choose a file and it will work fine.

2- As permission was granted, choosing a file from what ever folder will work, except if I try from Downloads folder it won’t work. I tested on Huawei Y9 and emulator with API 28 android 9 it did not work. However, I tested on Samsung note 4 it did work !. Both the Y9 and emulator have SD that could be the reason.

*if files were chosen from android app named “Files” there will be no issues.

any solution for this issue? :thinking:

2019-06-26T20:00:00Z

code:

upload(file) {
    this.androidPermissions.checkPermission(this.androidPermissions.PERMISSION.WRITE_EXTERNAL_STORAGE).then(res => {
      this.androidPermissions.requestPermission(this.androidPermissions.PERMISSION.WRITE_EXTERNAL_STORAGE).then( per => {
        this.fileChooser.open().then((path) => {
          this.filePath.resolveNativePath(path).then(nativeFilePath => {
            console.log(nativeFilePath);
            this.setFileName(file, nativeFilePath);
  
            this.setFilePath(file, nativeFilePath)
  
            setTimeout(()=>{ 
              this.checkFile(file)
            }, 1000)
  
          }).catch(err => console.log('ERROR: '+JSON.stringify(err)));
  
        }).catch(e => console.log('uri'+JSON.stringify(e)));
      }).catch(err => {
        console.log(err);
      });
    }),(err => {
      this.androidPermissions.requestPermission(this.androidPermissions.PERMISSION.WRITE_EXTERNAL_STORAGE);
    });
  }

setFileName(file, Pathfile) {

    this.file.resolveLocalFilesystemUrl(Pathfile).then((res)=>{

      file.fileName = res.name;

    }).catch((err)=>{
      console.log("error name: "+ JSON.stringify(err));
    })
  }

  setFilePath(file, Pathfile) {

    this.file.resolveLocalFilesystemUrl(Pathfile).then((fileData)=>{
      if (Pathfile) {
        file.fileName = fileData.name;
        file.fileType = fileData.name.split(".").pop().toString(),
        file.filePath = fileData.nativeURL;
        
      }else {
        console.log("error: file path")
      }

    }).catch((err)=>{
      console.log("error file path: "+JSON.stringify(err));
    })
  }

From console log:

this is the path i get content://com.android.providers.downloads.documents/document/16

when trying to resolveNativePath(), I get this error message:

ERROR: "Attempt to invoke interface method ‘int android.database.Cursor.getColumnIndexOrThrow(java.lang.String)’ on a null object reference"

Update:

Tested on emulator and device with Android 6 API 23, Selecting files from “Downloads” folder worked without causing any issues:

  • path: content://com.android.providers.media.documents/document/image%3A40

  • resolveNativePath: file:///storage/emulated/0/Android/data/com.android.browser/files/Download/2019-06-27-10-02-12–1835644526.jpg

An image and PDF file were tested

Conclusion:

File Chooser has an issue with selecting files from “Downloads” folder. This issue arise in Android 7, 8, 9. On android version 6, file chooser worked normally.

project info:

Ionic:

   Ionic CLI          : 5.1.0 (C:\Users\asalhajri\AppData\Roaming\npm\node_modules\ionic)
   Ionic Framework    : ionic-angular 3.9.2
   @ionic/app-scripts : 3.1.11

Cordova:

   Cordova CLI       : 8.1.2 (cordova-lib@8.1.1)
   Cordova Platforms : android 7.1.4
   Cordova Plugins   : cordova-plugin-ionic-keyboard 2.1.2, (and 15 other plugins)

Utility:

   cordova-res : 0.3.0
   native-run  : 0.2.5

System:

   NodeJS : v8.11.3 (C:\Program Files\nodejs\node.exe)
   npm    : 6.9.0
   OS     : Windows 10

Am I the only one who face this issue? :upside_down_face:

I’ve got the same problem. No solutions yet.

hi did you find any solution for this same issue for me and even “resolveNativePath” is not working for IOS to get filepath. please let me know if you find any solution

Thanks

I’m currently having the same problem when trying to access sub-folders in the downloads folder.