File Chooser URL issue

Hi,

I am using this plugin for getting files

when I select a pdf file from Downloads folder it is giving me uri as “content://com.android.providers.downloads.documents/document/1015”

but if i select another files like zip or png it gives me perfect path

content://com.android.providers.downloads.documents/document/raw%3A%2Fstorage%2Femulated%2F0%2FDownload%2Fwws.zip

content://com.android.providers.downloads.documents/document/raw%3A%2Fstorage%2Femulated%2F0%2FDownload%2Fopacity.png

Can anyone suggest me how do I get the path from it in the form of “file://…”.

I have tried these 2 but no success yet:
FilePath.resolveNativePath
normalizeURL

reply me if you have any solution

thanks

you need resolveLocalFilesystemUrl from the FileManager Plugin

Hi Aaron,

Thanks for replying,

I have used it as you suggested:

this.file.resolveLocalFilesystemUrl(uri).then((files)=>{
          console.log("files",files);
        }).catch((error) => { console.log("error", error) });

It still returns as:

filesystem: FileSystem {name: "content", root: DirectoryEntry}
fullPath: "/com.android.providers.downloads.documents/document/1015"
isDirectory: false
isFile: true
name: "1015"
nativeURL: "content://com.android.providers.downloads.documents/document/1015"

Which is the original url
I know from android perspective you need to get it from content provider.

+1 the same is happening in my app, only with .PDF files
EDIT 1: If you move the .pdf file outside of the Downloads folder it seems to work.
EDIT 2: 1. I downloaded the file that i choose outside of the Downloads folder 2. It was downloaded into Downloads folder, but this time i can select it. Might be this only for old pdfs?
EDIT 3: I am 90% sure this only happens with old PDF. I have downloaded some tales in pdf and these files have no problem.
EDIT 4: Suddenly started working with every pdf even if old…

This thread is a bit old, but for people coming across it now, try not to rely on file URLs. See this post.

Did you guys figured out the solution? I have exact same problem. What @rapropos suggest does not solve the problem. I still can’t get file extension

Ok, I finally got the solution

import { FileChooser } from '@ionic-native/file-chooser';
import { FilePath } from '@ionic-native/file-path';

chooseFileForAndroid() {
    this.fileChooser
      .open()
      .then(url => {
        this.filePath.resolveNativePath(url)
          .then(filePath => {
                console.log(filePath);
          })
          .catch(err => console.log(err));
      })
      .catch(e => {
        console.log(e);
      });
  }

This will give you the proper file path, file name. You will be able to get extension from it as well.