I am working on to read PDF data (not pdf url) from a post api and open the pdf using the pdf viewers installed on phone in my IONIC 4 android app. My File transfer plugin gives error with error code 2 on downloading that file. Here is my code which I have written. May I know where I went wrong?
my.ts file
var apiData="https://kairavforex.com/media/documents/reports/hello_TYUtZF5.pdf";
var sdsn={
path:apiData
}
this.http.post('https://kairavforex.com/api/download_report/',sdsn,{'Content-Type': 'application/json','Authorization': "Token" + " " + this.authToken})
.then(data=>{
console.log(data.data)
const fileTransfer: FileTransferObject = this.transfer.create();
fileTransfer.download(data.data, this.file.externalDataDirectory + 'file.pdf').then((entry) => {
this.fileOpener.showOpenWithDialog(entry.toURL(), 'application/pdf')
.then(() => console.log('File is opened'))
.catch(e => console.log('Error opening file', e));
}, (error) => {
console.log(error)
});
})
Here is the image of the error and my pdf response which is correct because when I save the same to my pc aspdf and open it works fine