java - Multiple file upload with Spring 3 -
i need load unknown number of files @ once. found example, , works known amount of files:
markup:
<form method="post" enctype="multipart/form-data"> <input name="files[0]" type="file" /> <input name="files[1]" type="file" /> <input type="submit" value="send"/> </form>
code:
@requestmapping(method = requestmethod.post) public string savephoto(@modelattribute("album") album album, bindingresult result, sessionstatus status, multipartfileuploadbean file) { list<multipartfile> images = file.getfiles(); (multipartfile photo : images) { ... } return "redirect:/albums/"+album.getid(); }
multipartfileuploadbean:
public class multipartfileuploadbean { private list<multipartfile> files; public void setfiles(list<multipartfile> files) { this.files = files;} public list<multipartfile> getfiles() { return files;} }
yes, works, not know how user wants upload photo in album. , use:
<input name="files[]" type="file" multiple="multiple" />
i'll error.
request processing failed; nested exception java.lang.numberformatexception: input string: ""
i looking how use multiple = "multiple", found none. hope help.
in xhtml:
<input name="files" type="file" multiple="multiple" />
alter request-mapped method:
@requestmapping(method = requestmethod.post) public string savephoto(multipartrequest multipartrequest, ...) { list<multipartfile> images = multipartrequest.getfiles("files"); ... }
Comments
Post a Comment