Submitting form data via HTTP post will look like this:
saveDataFile(mutlidata,id,value): Observable<Response> {
var _url = 'http://xxxx.xxx.xxx';
var saveDataURL = _url + '/' + id;
var _this = this;
let headers = new Headers();
headers.append('Content-Type', 'multipart/form-data');
let options = new RequestOptions({ headers: headers });
const frmData = new FormData();
frmData.append("file",JSON.stringify(mutlidata),'sample.json');
frmData.append("dataCheck",value);
return this.http.post(saveDataURL,frmData, options).pipe(
map((res: Response) => {
return res;
}),
catchError(this.handleError),);
}
The variable multidata will contain:
[["fakepath/test1.JPG","ea305e-be9d"],["fakepath/test2.JPG","489ce580-c50e-40e6-b1ab-71c7827f636c"]]
The id will be 15asdas6asd6
The value will either be true or false
It seems that the form data is not being sent properly. Upon debugging and checking frmdata in return this.http.post(saveDataURL,frmData, options), it displays form.entries, values, etc.
In the sample.json file, I am appending the form data as follows:
frmData.append("file",JSON.stringify(mutlidata),'sample.json');
Here, the term "file" indicates that the data needs to be sent to the API using that keyword.