Structure of input data in a content-type: Angular form-data


They are asking me to send some data through the post method. I leave the code first:

addImage(image, params): Observable<any> {

const httpOptions = {
  headers: new HttpHeaders({
    'Authorization': this.token,
    'Content-Type': 'multipart/form-data',
    'Content-Disposition': 'form-data; filename=${}'
}; = params; = image;
return ,, httpOptions);

The request is not worth it, I think what they expect to receive is the data of a form (form that neither exists nor will exist). There is some way to simulate how that entry would be. That is, how to simulate the input that the form would give us when launching?.


asked by Findelias 23.11.2018 в 15:00

1 answer


What you have to do is create a FormData and add the image like this:

const fd= new FormData();
fd.append('nombre',image,; //el nombre del fichero es opcional

and add the rest of values of the form of similar way:

const httpOptions = {
  headers: new HttpHeaders({
    'Authorization': this.token,
    'Content-Type': 'multipart/form-data'
answered by 23.11.2018 / 15:38