Hi, there I’m working on a project and wanted to know how can I upload pdf file and images to rest api as I tried with filetransfer plugin but was unable to send. Then I was suggested to send in the form of formdata.
Can anybody help me with that.
Thanks!!
below is my code…
this.pdfObj = pdfMake.createPdf(docDefinition);
(this.platform.is('cordova'))
this.pdfObj.getBuffer((buffer) => {
var blob = new Blob([buffer], { type: 'application/pdf' });
// Save the PDF to the data Directory of our App
this.file.writeFile(this.file.dataDirectory, 'myletter.pdf', blob, { replace: true })
// Open the PDf with the correct OS tools
// this.fileOpener.open(this.file.dataDirectory + 'myletter.pdf', 'application/pdf');
// console.log("pdf");
});
console.log("got till here")
//Show loading
this.loading = this.loadingCtrl.create({
content: "Uploading..."
});
this.loading.present();
const fileTransfer: FileTransferObject = this.transfer.create();
//option transfer
let options: FileUploadOptions = {
fileName: this.myletter,
chunkedMode: false,
httpMethod: 'post',
params : {'i13': this.myletter}
}
//file transfer action
fileTransfer.upload(this.myletter, 'myapi.php', options)
.then((data) => {
this.loading.dismissAll()
console.log('Image succesful uploaded.');
}, (err) => {
this.loading.dismissAll()
console.log('Error while uploading file.');
});
this.navCtrl.push(SecThreePage)
}