0

I'm trying to send the following request through my Controller

@RequestMapping(value = {"/fileupload"}, method = RequestMethod.POST, consumes = {MediaType.ALL_VALUE)
    @ResponseStatus(value = HttpStatus.OK)
    @ResponseBody
    public Object fileupload(@RequestPart MultipartFile[] file,@RequestPart DTO dto) throws Exception {

    }

But I get the following error

CORSFilter HTTP Request: POST

org.springframework.web.HttpMediaTypeNotSupportedException: Content type 'application/octet-stream' not supported
at org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodArgumentResolver.readWithMessageConverters(AbstractMessageConverterMethodArgumentResolver.java:226)
at org.springframework.web.servlet.mvc.method.annotation.RequestPartMethodArgumentResolver.resolveArgument(RequestPartMethodArgumentResolver.java:132)
Romil Patel
  • 12,879
  • 7
  • 47
  • 76
rParvathi
  • 1,939
  • 2
  • 16
  • 21

1 Answers1

0

I face the same issue and i resolved this on Angular side using below code. On the server side it is fine, you can even remove consume.ALL

url: 'api/import_bot',
data: {
       file: vm.file,
       DTO: new Blob([angular.toJson(DTO)], {type : 'application/json'})
}

You have to send file and wrap the DTO as BLOB and set its content-type.