In my angular4 application, I am trying to upload a video to a server. But no matter what I add to the content type, this always results in an error from the server. In angular 1, the same api hits using {'Content-Type': undefined}
I tried the same in angular, but it works. Data and everything is correct. I tried with a set of content like below
headers.append('Content-Type', 'multipart/form-data');
headers.append('Authorization', token);
headers.set('Accept', 'application/json');
as well as below
headers.append ('Content-Type', undefined);
below is the http request method:
public uploadVideo(formData: any) {
var Upload = this.baseUrl + this.ngAuth.getApiUrl('Upload');
var authData = JSON.parse(this.localStorage.localStorageGet('token'));
var token = 'Bearer ' + authData.token;
var self = this;
var headers = new Headers();
headers.append('Content-Type', 'multipart/form-data');
headers.append('Authorization', token);
headers.set('Accept', 'application/json');
return this.http.post(Upload , formData, { headers: headers, method: 'POST' })
.map((res: Response) => res.json());
}
Please guide! Thanks
source
share