'Why FormData object is empty even after I use append?
I tried the following code: (This is my service file in angular posts.service.ts)
updatePost(id: string, title: string, content: string, image: File | string) {
let postData: Post | FormData;
console.log(id);
if(typeof(image) === 'object'){
console.log("Image is object");
const postData = new FormData();
postData.append('id',id);
postData.append('title',title);
postData.append('content', content);
postData.append('image', image, title);
console.log(postData)
} else {
console.log("In else!")
postData = { id: id, title: title, content: content, imagePath: image };
}
When I check console.log(postData)
, it is empty.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|