lundi 20 avril 2015

Spring MultiPart MediaType Unsupported

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.

Aucun commentaire:

Enregistrer un commentaire