问题描述
修改
此问题与以下内容不同: jQuery Ajax文件上传:必需的MultipartFile参数'file'不存在不同之处在于它们使用jQuery和Ajax,而我使用REST客户端-邮递员"
This question is different from: jQuery Ajax file upload : Required MultipartFile parameter 'file' is not presentThe difference is that they use jQuery and Ajax, while I use a REST client - 'Postman'
因此,我没有将Content-Type设置为false,而是将其完全删除.
So instead of setting Content-Type to false, I had to remove it altogether.
此外,当我寻找有关邮递员"的答案时,我相信人们会跳过其中包含jQuery和Ajax的问题,这就是我发生的事情
Also, when searching for answers about 'Postman', I believe people will skip questions that have the words jQuery and Ajax in them, this is what happened to me
结束编辑
我正在Java8上使用Spring MVC Web应用程序,并在tomcat7.x上运行它.春季版本为:4.2.6.RELEASE
,而Javax Servlet版本为:3.0.1
I'm using Spring MVC web application on Java8 and running it on tomcat7.x.Spring version is: 4.2.6.RELEASE
and javax servlet version is: 3.0.1
context.xml
...
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<!-- max upload size in bytes -->
<property name="maxUploadSize" value="5242880" /> <!-- 5MB -->
<!-- max size of file in memory (in bytes) -->
<property name="maxInMemorySize" value="1048576" /> <!-- 1MB -->
</bean>
...
controller.java
...
@RequestMapping(method = RequestMethod.POST, consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
@ResponseStatus(value = HttpStatus.CREATED)
public void importTranslations(@RequestParam (name = "myfile") MultipartFile myfile) {
myService.doSomething(myfile);
}
...
这是问题
我使用邮递员发送* .zip文件.路径正确,一切看起来不错,但是spring抛出异常:所需的MultipartFile参数'myfile'不存在"
I use Postman to send a *.zip file. The path is correct and everything looks good, but spring throws an exception:"Required MultipartFile parameter 'myfile' is not present"
以下是Postman的屏幕截图:因此该文件在那里,键名正确.一切似乎都还可以,但是,我得到了错误
Here is the screenshot from Postman:So the file is there and the key name is correct.Everything seems OK, and yet, I get the error
推荐答案
在stackoverflow中进行了大量搜索之后,我发现了以下问题: jQuery Ajax文件上传:必需的MultipartFile参数'file'不存在
After a lot of searching here in stackoverflow, I found this question: jQuery Ajax file upload : Required MultipartFile parameter 'file' is not present
我尝试将Postman中的Content-Type标头设置为false并收到错误.当我删除Content-Type标头时,它起作用了!
I tried setting the Content-Type header in Postman to false and got an error.When I removed the Content-Type header, it worked!!
希望这对某人有帮助
这篇关于邮递员-所需的MultipartFile参数不存在-Spring,Java的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!