yeah,our customer want to upload more than one file. we use spring 3 mvc. the official example like this:
markup:
<form method="post" action="/form" enctype="multipart/form-data">
<input type="text" name="name"/>
<input type="file" name="file"/>
<input type="submit"/>
</form>
code:
@RequestMapping(value = "/form", method = RequestMethod.POST)
public String handleFormUpload(@RequestParam("name") String name,
@RequestParam("file") MultipartFile file) {
if (!file.isEmpty()) {
byte[] bytes = file.getBytes();
// store the bytes somewhere
return "redirect:uploadSuccess";
} else {
return "redirect:uploadFailure";
}
}
there is only one file,so i can write the file input name in the method. but what should i do if i want to upload many files. i could not write all the file input names because if is generated by the js code. i only know that its name like 'attach_' then ,what should i write in the method ? if i write like this
@RequestParam() MultipartFile file
or
@RequestParam("attach_") MultipartFile file
i'll get a error.