How to send multi-page file from angular 4 using http

I need to send a file using the multi-page file that my spring controller expects.

public void test(@RequestParam("file") MultipartFile file) {}

I know what I need to use FormData, but I was not able to get it to work. Here is my code:

this.headers = new Headers({ 'Content-Type': 'multipart/form-data'});
this.options = new RequestOptions({ headers: this.headers });

return this.http.post(environment.SERVER_ENDPOINT + 'parameters/area', formData, options)
  .toPromise()
  .then(this.extractData)
  .catch(this.handleError);
+4
source share

Source: https://habr.com/ru/post/1689477/


All Articles