将文件从Angle 5发送到Java后端

时间:2019-02-06 17:56:25

标签: angular angular-httpclient

我是Angular的初学者,我成功将File上传到angular5,现在我无法将它(pdf)从angular发送到后端。我试图找到一些教程或文档,但是没有用。因此,在发现错误方面会有所帮助。

角度服务:

const httpOptions = {
      headers: new HttpHeaders({  
        'Content-Type':'application/pdf; charset=utf-8',    
      })
    };
return this.http.post("api/magazines/add", file, httpOptions);


Controller - backend:
@RequestMapping(value="/add",method = RequestMethod.POST, consumes = "application/pdf")
    private ResponseEntity<String> addMagazine(@RequestBody File file) {
...
}

错误是:

error: {timestamp: "2019-02-06T17:46:26.998+0000", status: 415, error: "Unsupported Media Type", message: "Content type 'application/pdf;charset=utf-8' not supported" ...}

0 个答案:

没有答案