@antony110994 wrote:
my goal is to send a POST request with data in his body and receive a PDF file to be saved and then to open. I created two functions to do this thing with different approaches but both give me problems .
1)prova(){
let link = 'http://www.istruzione.it/esame_di_stato/201516/Italiano/Ordinaria/P000_ORD16.pdf'; let dir: string; if(this.platform.is('android')){ dir = cordova.file.externalDataDirectory; } if(this.platform.is('ios')){ dir = cordova.file.dataDirectory; } alert(dir); let data = { nome: "antonio", cognome: "amodeo" }; let options = { params: data }; let fileTransfer = new Transfer(); fileTransfer.download(link, dir + 'abc.pdf', true, options).then((fileEntry) => alert("okey")); this.platform.ready().then(() => { cordova.plugins.fileOpener2.open( dir + "/abc.pdf", 'application/pdf', { error : function(e) { console.log('Error status: ' + e.status + ' - Error message: ' + e.message); }, success : function () { console.log('file opened successfully'); } } ); });
}
This first solution makes me download the pdf file and open it but also does a POST request but a normal GET .
2)
prova2(){
let link = 'http://www.istruzione.it/esame_di_stato/201516/Italiano/Ordinaria/P000_ORD16.pdf'; let date = { nome: "antonio", cognome: "amodeo" }; this.http.post(link,date).subscribe(data => { alert(cordova.file.externalDataDirectory); File.createFile(cordova.file.externalDataDirectory, 'abc.pdf', true).then((fileEntry) => { fileEntry.createWriter((fileWriter) => { fileWriter.onwriteend = () => { alert('File writer - write end event fired...'); }; fileWriter.onerror = (e) => { alert('file writer - error event fired: ' + e.toString()); }; fileWriter.write(data.text()); this.platform.ready().then(() => { cordova.plugins.fileOpener2.open( cordova.file.externalDataDirectory + "/abc.pdf", 'application/pdf', { error : function(e) { console.log('Error status: ' + e.status + ' - Error message: ' + e.message); }, success : function () { console.log('file opened successfully'); } } ); }); }); }); });
}
the second solution sends the POST request with the right data, but the downloaded file when opened it has the right number of pages but are in white. In your opinion how could I do?
Posts: 1
Participants: 1