How to read choosen file content in Cordova app?

847 Views Asked by At

I want to perform the below task in my Cordova android app

  • Give the user the ability to choose any txt file from his device.
  • Then the file content I need to read in my app
  • Modify file content and store it in another txt file

For Choosing text file I have used

cordova-plugin-filechooser

And written code as below

fileChooser.open(function (uri) {
  alert(uri);      
});

Which correctly opens the dialog to choose a file. After choosing the file I am getting uri as below

content://com.android.providers.downloads.documents/document/446

Now how I should read the file content? I am also using

cordova-plugin-file

I have checked code for cordova-plugin-file and we need to use fileEntry, how should I accomplish that?

1

There are 1 best solutions below

2
On

You could use instead cordova-plugin-filepath then do

let path = FilePath.resolveNativePath('content://...', successCallback, errorCallback);