Quantcast
Channel: Ionic Framework - Ionic Forum
Viewing all articles
Browse latest Browse all 49248

ionic ,cannot get text of picken file in DocumentPicker [on hold]

$
0
0

@ionian wrote:

i am using a DocumentPicker to pick text files. The goal is to get the text of the picken file and sisplay it on the screen. Here i open the document picker. openDocumentPicker(){

var failure = function(message) { console.log("Error sending the email "); } cordova.exec(this.successCall, failure, “DocumentPicker”, “getFile”, [ JSON.stringify(‘all’) ]); this.docPicker.getFile(‘all’) // DocumentPickerOptions.IMAGE and DocumentPickerOptions.PDF are also available .then(uri => console.log("uri= "+uri)) .catch(e => console.log("err= "+e)); }

successCall(message) { console.log("Succeeded2 "+message); HomePage.currentFileUrl=message;//‘assets/myFile.pdf’; HomePage.filePicked=true; } In the success call back i get the url in the format: e.g file:/// … .rtf Then i am trying to get the text of the file. showTextOfFile(fileUrl:any){//fileUrl=’’ The first problem is that the resolveNativePath is not working: this.filePath.resolveNativePath(fileUrl).then((path)=>{ //not going in here. console.log(path); }); Then i am trying to use readAsText in the file and it does not work as well. let path = fileUrl.substring(0, fileUrl.lastIndexOf(’/’)); let file = fileUrl.substring(fileUrl.lastIndexOf(’/’)+1, fileUrl.length);

this.file.readAsText(path,file).then((data)=>{
  //not going in here
  console.log(data);
}).catch(err=>console.log(err));

and then i am trying this code and it is not working as well.
this.file.readAsBinaryString(path, file)
.then(content=>{
  //not going in here.
  console.log("File-Content: "+ JSON.stringify(content));
})
.catch(err=>{
  console.log(err);
  alert(JSON.stringify(err));
});  

Finally ,i try to use FileReader and it is not working.
var reader = new FileReader();
reader.onload = function(e) {
  //not going in here.
  var text = reader.result;
  console.log("data31 "+text); 
}
reader.readAsText(fileUrl.files[0]);

I was wondering if you could help me ,please? Thank you in advance.

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 49248

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>