Required MultipartFile parameter 'file' is not present in spring mvc

匿名 (未验证) 提交于 2019-12-03 02:03:01

问题:

I am trying to add feature of uploading picture to my spring mvc application.

jsp part:

... 
...

configuration:

...   ... 

controller:

 @RequestMapping(value="/member/createCompany/uploadImage", method=RequestMethod.POST)     public @ResponseBody String handleFileUpload(             @RequestParam("file") MultipartFile file){         String name = "image_name";         if (!file.isEmpty()) {             try {                 byte[] bytes = file.getBytes();                 BufferedOutputStream stream =                         new BufferedOutputStream(new FileOutputStream(new File(name + "-uploaded")));                 stream.write(bytes);                 stream.close();                 return "You successfully uploaded " + name + " into " + name + "-uploaded !";             } catch (Exception e) {                 return "You failed to upload " + name + " => " + e.getMessage();             }         } else {             return "You failed to upload " + name + " because the file was empty.";         }     } 

After I selected picture I click upload and see error message:

HTTP Status 400 - Required MultipartFile parameter 'file' is not present 

What do I wrong?

回答1:

You have not specified the name attribute , @RequestParam("textFile") requires name ,

 


回答2:

add name attribute to "file" input tag



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!