Ionic file opener

Hi there

I am developing an app for android, ios and windows. One of the requirements is being able to download a pdf that is stored in the assets folder in the ionic app. I am using this plugin https://ionicframework.com/docs/native/file-opener/. I am executing this code as per the documentation.

this.fileOpener.open(‘assets/pdf-test.pdf’, ‘application/pdf’)
.then(() => console.log(‘File is opened’))
.catch(e => console.log(‘Error openening file’, e));

However I get the following error

“file not found”

Please help

Any help? I am avoiding setting platform specific paths so as to keep the code base standard

Hey @dhameergovind,

I don’t think you need file opener if it’s in the assets folder. I achieved something similar with:

constructor(
    public navCtrl: NavController,
    private http: Http,
    private storage: Storage,
    public popoverCtrl: PopoverController
  ) {
     this.http
       .get("assets/texts/text1.txt")
       .map(res => {
         return res.text();
       })
       .subscribe(data => {
        // work with data
       });
  }


Now, this was a text file, but, hopefully, it will help you.

@PavolGanzarcik Thanks for this but unfortunately no luck. Get back a weird result. Also tried with a text file just to check.

This starter repo has moved to the ionic-team/starters repo!