org.springframework.web.HttpMediaTypeNotSupportedException:不支持内容类型'application / octet-stream'

时间:2020-04-21 07:46:27

标签: reactjs spring spring-boot wordpress-rest-api

``@PostMapping(value = "/staff/saveStaff" , consumes=MediaType.MULTIPART_FORM_DATA_VALUE)
public String saveStaff(@RequestPart("staff") Staff staff,@RequestPart("profilePic") MultipartFile profilePic) {

    logger.debug(" Staff "+staff+":"+profilePic);
    return null;

}`

想在一个请求中发布Json对象和MultipartFile,尝试使用@ModelAttribute而不是@RequestPart来接收文件对象,但Staff对象为空。

试图更改媒体类型但不起作用,删除的媒体类型仍然不起作用,

React js中的Http请求:使用Axios

      var formData = new FormData();
      formData.append("profilePic",this.state.profilePic)
      formData.append("staff",{...this.state.staff})
      axios.post("/staff/saveStaff", 
        formData,
       {headers: {
           'Content-Type': 'multipart/form-data'
         }}
        )
          .then(res => {
            if (res.status === 200) {
              console.log("Saved");                 

            }
          })

0 个答案:

没有答案