在多部分请求中发送List <string>时出错

时间:2015-06-16 09:27:34

标签: spring spring-mvc spring-boot multipartform-data

我正在尝试向控制器服务发送多部分请求,如下所示

  @RequestMapping(value="/uploadFile", method=RequestMethod.POST)
    public void uploadApk(@RequestPart("fileName") String fileName, 
                    @RequestPart("md5") String md5, 
                    @RequestPart("userList") List<String> userList,
                    @RequestPart("file") MultipartFile file){
   ...
   ...
    }

调用上述函数的ajax请求是

  var formData = new FormData();
  formData.append("fileName",imgfileList[0].name);
  formData.append("md5",md5);
  formData.append("userList",userList);
  formData.append("file", imgfileList[0]); 

  $.ajax({
    url: urlPost,
    type: "POST",
    data: formData,
    dataType: "json",
    processData: false,
    enctype:'multipart/form-data',
    headers: {'Content-Type': undefined},
    success: function(data)
    {
        alert("File Uploaded!");
    }
 });

我试图关注this link

但是我收到了以下错误。

{"timestamp":1434485164651,"status":415,"error":"Unsupported Media Type","exception":"org.springframework.web.HttpMediaTypeNotSupportedException","message":"Content type 'application/octet-stream' not supported","path":"/uploadFile"}

我尝试调试错误,发现错误仅发生在&#34; @RequestPart(&#34; userList&#34;)列出userList &#34;。这是仅在发送字符串数组时出现的错误。

如何解决问题?

0 个答案:

没有答案