发送的图像和JSON对象/ Angular的问题

问题描述 投票:-1回答:1

我对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"
}
angular http-post
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.