我对Angular Post方法有疑问。我希望o将图像和模型发送到服务器。这是我的服务:
pushFileToStorage(file: File, ct:CategoryModel): Observable<HttpEvent<{}>> {
const formdata: FormData = new FormData();
formdata.append('file', file);
const req = new HttpRequest('POST', 'api/cateogry/saveCategory', {formdata ,ct} ,{
reportProgress: true,
responseType: 'text'
});
return this.http.request(req);
}
这是我的commponenet:
this.uploadService.pushFileToStorage(this.currentFileUpload, this.category).subscribe(event => {
if (event.type === HttpEventType.UploadProgress) {
this.progress.percentage = Math.round(100 * event.loaded / event.total);
} else if (event instanceof HttpResponse) {
console.log('File is completely uploaded!');
}
});
我有错误:
{
"timestamp": "2019-02-25T13:44:22.093+0000",
"status": 415,
"error": "Unsupported Media Type",
"message": "Content type 'multipart/form-data;boundary=--------------------------125126563049882524399172;charset=UTF-8' not supported",
"path": "/api/product/createCategory"
}