[英]Spring MultiPart MediaType Unsupported
I'm actualy trying to upload a file on my Spring server. 我实际上是想在Spring服务器上上传文件。 The fact is that I always have a 415 (Unsupported Media Type) error without any error in server's log.
事实是,我总是遇到415(不受支持的媒体类型)错误,而服务器日志中没有任何错误。
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 为了解决这个问题,我还添加了MultipartResolver
@Bean
public CommonsMultipartResolver getMultipartResolver() {
return new CommonsMultipartResolver();
}
It's probably something stupid, but I can't find what I missed. 这可能是愚蠢的,但是我找不到我错过的东西。
From documentation of MultipartResolver : 从MultipartResolver的文档中:
To define an implementation, create a bean with the id "multipartResolver" in a DispatcherServlet's application context
要定义实现,请在DispatcherServlet的应用程序上下文中创建一个ID为“ multipartResolver”的bean。
Declare the CommonsMultipartResolver
as below: 声明
CommonsMultipartResolver
如下:
@Bean(name = "multipartResolver")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.