I am attempting to pass a file to Web API from an Angular 2 app, and the actual file data does not get sent.
Here is my angular 2 service code:
var headers = new Headers();
headers.append('Content-Type', 'multipart/form-data');
var formData = new FormData();
formData.append("file", file);
return this.http.post('http://myapiurl.com/files/upload', formData, { headers: headers }).map(res => res.json());
In the angular 2 docs, the POST method signature is as follows:
post(url: string, body: string, options?: RequestOptionsArgs) : Observable<Response>
There is no option to pass Form Data, or other object. Just a string in the bodys request. The current work around is to use javascript and regular xhr requests. There are obvious downsides to this like not being able to use observables, etc.
Any help on this would be greatly appreciated.