2

I have downloaded an pdf file from the server using Transfer Plugin and i am trying to open the file using InAppBrower plugin i am not getting anything. i mean nothing is happening.

fileTransfer.download(url, this.file.dataDirectory + file.filename,false,{
        headers: {
            'authorization': 'bearer xxxx'
        }
    }).then((entry) => {
      console.log('download complete: ' + entry.toURL());
      console.log(entry.nativeURL);
      const browser = this.iab.create(entry.nativeURL, '_system', 'location=yes'); //here the inappbrowser plugin code.
    }, (error) => {
      // handle error
      console.log(error);
      console.log('ERROR');
    });

my console.log(entry.nativeURL); prints this path file:///data/user/0/com.schneider.and/files/Attendance_Policy_Ver_1.0.pdf

Mohan Gopi
  • 7,606
  • 17
  • 66
  • 117

2 Answers2

0

Try putting the nativeUrl in the browserURL and see if you could jump to the exact .pdf....

Then try

fileTransfer.download(url, this.file.dataDirectory + file.filename,false,{
        headers: {
            'authorization': 'bearer xxxx'
        }
    }).then((entry) => {
      console.log('download complete: ' + entry.toURL());
      console.log(entry.nativeURL);
      let browser=new InApp Browser(entry.nativeURL,'_blank');
    }, (error) => {
      // handle error
      console.log(error);
      console.log('ERROR');
    });

And import InAppBrowser from 'ionic-native'

import {InAppBrowser} from 'ionic-native';
priyank bhardwaj
  • 119
  • 2
  • 15
  • i am getting blank screen even after trying the above answer – Mohan Gopi Jun 08 '17 at 12:01
  • ok...did you try pasting the link in browser's URLbar? If yes then what did you get? And are you able to run the same in chrome developer tools? – priyank bhardwaj Jun 08 '17 at 12:04
  • the link in the browser url bar will not show the pdf because it needs headers object if you see in my above question i have given authorization for downloading the file so my file is in the path that i have mentioned in my question using that path only i have to open in inappbrowser – Mohan Gopi Jun 08 '17 at 12:06
  • When you're running the app, then what URL are you getting in the URLbar? – priyank bhardwaj Jun 08 '17 at 12:10
  • same url that you see on my question – Mohan Gopi Jun 08 '17 at 12:35
0

i use this code and its works for me

showDocument(){
      const options: DocumentViewerOptions = {
        title: 'My PDF'
      }
      const imgeLocation = `${cordova.file.applicationDirectory}www/assets/imgs/${'Jainbhajan-Jeevan-Saar-By-Nirmal-Gangwal-1-ilovepdf-compressed (1).pdf'}`;
      this.document.viewDocument(imgeLocation, 'application/pdf', options)
    }
STF
  • 1,485
  • 3
  • 19
  • 36
Rijwandeltax
  • 152
  • 1
  • 13