我想将图片从jsp页面中的文件上传到aws bucket
我使用此代码:
jsp文件标签:
<input type="file" name="file" id="file" onchange="changePicture()">
控制器:
@RequestMapping(value = "/saveContact", method = RequestMethod.POST)
public @ResponseBody ModelAndView saveContact(@ModelAttribute Contacting Contacting,ModelAndView modelndView,HttpServletRequest request ,
@RequestParam("file") MultipartFile file) throws Exception {
if (!file.isEmpty()) {
byte[] bytes = file.getBytes();}...(Is not all function)
的pom.xml:
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.3.1</version>
</dependency>
MvcConfigration.java:
@Bean(name = "multipartResolver")
public StandardServletMultipartResolver resolver() {
return new StandardServletMultipartResolver();
}
当我运行它时,我收到了这个错误:
Required MultipartFile parameter 'file' is not present
我的代码中有哪些不正确的内容?
答案 0 :(得分:1)
下面的示例适用于XML配置,但您可以进行调整。
<servlet>
<servlet-name>spring-web</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
<multipart-config>
<location>/tmp</location>
<max-file-size>20848820</max-file-size>
<max-request-size>418018841</max-request-size>
<file-size-threshold>1048576</file-size-threshold>
</multipart-config>
</servlet>