I have an Angular app where I want to implement upload of images to the server. I'm stuck on the moment where I must append chosen file to the newly created FormData. Here is my TypeScript component relevant part:
imageData: File = null;
avatar = null;
fileProgress(fileInput: any) {
this.imageData = <File>fileInput.target.files[0];
this.avatar = new FormData();
this.avatar.append('avatar', this.imageData);
console.log(this.avatar, this.imageData)
}
This is what appears in console - FormData {} File {name: "background.jpg", lastModified: 1579183010623, lastModifiedDate: Thu Jan 16 2020 15:56:50 GMT+0200, webkitRelativePath: "", size: 8272, …}
So basically I don't understand why I can't append already existing this.imageData with value to this.avatar, when I try to append it, it's value doesn't change and i still have empty array = FormData {}. Any help would be appreciated.
this.avatar.get('avatar')?File {name: "c6a60a43d7.png", lastModified: 1578421705098, lastModifiedDate: Tue Jan 07 2020 20:28:25 GMT+0200 (Восточная Европа, стандартное время), webkitRelativePath: "", size: 257877, …}forthis.avatar.get('avatar')