I'm making an APP of my homepage. And I got a problem in making a 'Writing page'. I have to POST some data and image. And I can't get how to POST image!
I searched and found this code. but it's still not working... I think the FormData
is Empty. Can you tell me why the FormData
is empty or Can you show me a better way to POST Image and Texts in Ionic 2
?
This is my HTML code..
<input type="file" (change)="write($event)"/>
and my TypeScript code
write(event) {
let file = event.srcElement.files.item(0);
let formData: FormData = new FormData();
let headers = new Headers({
'Content-Type': 'multipart/form-data'
});
let options = new RequestOptions({
headers: headers
});
formData.append('bf_file', file, file.name);
formData.append('wr_subject', 'Just Testing');
formData.append('wr_content', 'Some content...');
formData.append('bo_table', 'table');
this.http.post('http://www.myhomepage.com/write_update.php', formData, options).subscribe(res => {
console.log(res.text());
});
}
Please help me...