0

I'm actualy trying to upload a file on my Spring server. The fact is that I always have a 415 (Unsupported Media Type) error without any error in server's log.

There is my code :

Client side :

  journal.import= function(id, file, callbackSuccess, callbackError){
        var fd = new FormData();
        fd.append('file', file);
        $http.post(config.API_URL +"/newspapper/import/"+id, fd, {
        transformRequest: angular.identity,
        headers: {'Content-Type': undefined}
        }).success(callbackSuccess).error(callbackError);
    }

Server side :

@POST
@Path("/import/{id}")
@Override
public void importJournalTypeConcurrent(@PathParam("id") long id,
        @RequestParam("file") MultipartFile file) {
    System.out.println(file.getName());
}

To solve this problem, I've also add a MultipartResolver

@Bean
public CommonsMultipartResolver getMultipartResolver() {
    return new CommonsMultipartResolver();
}

It's probably something stupid, but I can't find what I missed.

Pierre-Alexandre Moller
  • 2,354
  • 1
  • 20
  • 29

1 Answers1

0

From documentation of MultipartResolver:

To define an implementation, create a bean with the id "multipartResolver" in a DispatcherServlet's application context

Declare the CommonsMultipartResolver as below:

@Bean(name = "multipartResolver")
Mithun
  • 7,747
  • 6
  • 52
  • 68