this.headers = new Headers();
this.headers.append('Content-Type', 'multipart/form-data;boundary=--boundary');
.....
let data = new FormData();
data.append('file', file);
data.append('fileName', file.name);
data.append('fileSize', file.size.toString());
data.append('fileType', file.type);
data.append('fileLastMod', file.lastModifiedDate);
.....
let url = 'http://api.********.com/gallery/'+ this.selectedCategory;
this._http.post(url, data, {headers : this.headers})
.toPromise()
.catch(reason => {
console.log(JSON.stringify(reason));
}).then(result => {
console.log('From Promise:', result);
});
如果要在请求中发送formdata对象,则不需要导入content-type。
Angular HTTP方法支持多部分类型,其中HttpClient也支持具有默认reportProgress功能的multipart,它将通知上传状态
解决方案 - 使用HTTP方法,它将自己设置边界。