Error while sending List<String> in multipart request

1k Views Asked by At

I am trying to send a multipart request to a controller service which looks like following

  @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){
   ...
   ...
    }

The ajax request for calling the above function is

  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!");
    }
 });

I have tried to follow this link

But i am getting the following error.

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

I tried to debug the error and found that the error was coming only for "@RequestPart("userList") List userList". That is the error appears only while sending an array of strings.

How do I solve the problem ?

0

There are 0 best solutions below