I'm sending images and other form data through multi-part requests. When I call the api using PostMan the image is successfully adding. But I;m getting an error from back-end when I call the same API using angular code.
Component.ts
addOffer() {
this.formData = new FormData();
this.formData.append('promotion', this.file, this.file.name);
this.formData.append("main_text", this.offerAddForm.controls['title'].value);
this.formData.append("type", '1');
this.formData.append("footer_text", 'rdy');
this._addOfferService.addOffer(this.formData)
.pipe(first())
.subscribe(
data => {
console.log("Yo yo "+data);
},
error => {
console.log("An Error Occurred add notify ", error);
});
}
Service.ts
addOffer(formData) {
const token = this.authService.getToken();
let headerOptions = new HttpHeaders({
'Content-Type': 'multipart/form-data',
'Authorization': 'Bearer '+token
});
const url = environment.baseURL + 'promotions';
return this.http.post<any>(url, formData, {headers: headerOptions})
.pipe(map(response => {
return response;
}));
}
Update: Error From back-end:
An invalid promotion type.
Request Payload :
What I'm doing wrong here ?