Hi friends,I want to upload two images after taking photos from camera.I want append them to form data but they are not uploading.Please help me. My code is
export class MyClass{
/PAN and Address are the two images I want to upload.I am saving the data in the following variables/
panCardImageData: any;
addressCardImageData: any
constructor(…){}
..................................
…
/I added a button in html view.On pressing it it calls takePANPhoto() method/
takePANPhoto() {
this.camera.getPicture({
quality: 100,
destinationType: this.camera.DestinationType.FILE_URI,
sourceType: this.camera.PictureSourceType.CAMERA,
encodingType: this.camera.EncodingType.PNG,
saveToPhotoAlbum: true
}).then(imageData => {
this.uploadPANPhoto(imageData);
}, error => {
});
}
private uploadPANPhoto(imageFileUri: any): void {
this.file.resolveLocalFilesystemUrl(imageFileUri)
.then(entry => (entry).file(file => this.readPANFile(file)))
.catch(err => console.log(err));
}
private readPANFile(file: any) {
const reader = new FileReader();
reader.onloadend = () => {
const formData = new FormData();
const imgBlob = new Blob([reader.result], { type: file.type });
formData.append(‘file’, imgBlob, file.name);
this.panCardImageData=formData;
//I saved the formData in panCardImageData
};
reader.readAsArrayBuffer(file);
}
…
/*On upload documents the method onKycSubmit() is called */
onKycSubmit() {
let formData: FormData = new FormData();
formData.append("pan", this.panCardImageData);
formData.append("kyc", this.addressCardImageData);
this.verifyService.kycFilesUpload("PANCARD", this.panCardImageData).subscribe((res) => {
this.navCtrl.push(VerifyPage);
}, (error) => {
console.log(error);
});
}
/*This is my API url in VerifyService */
kycFilesUpload(fileName:any,formData:any){
return this.http.post(this.funService.apiUrl +fileName,formData);
}
Please explain how to append image data collected from take picture to formdata