i'm trying implement file upload functionality in spring application.
currently, using multiple
attribute of html5 forms send multiple files server. files htting controller, having issues transferring them server destination.
@requestmapping(value = "/upload", method = requestmethod.post) public string handleupload(@requestparam("files[]") list<multipartfile> files, model model) { string filename; file transferfile; string filepath = system.getproperty("catalina.base") + file.separator + "resources" + file.separator; arraylist<file> filelist = new arraylist<file>(files.size()); arraylist<string> filenamelist = new arraylist<string>(files.size()); (multipartfile file : files) { filename = filepath + file.getoriginalfilename(); transferfile = new file(filename); filenamelist.add(filename); try { if (transferfile.exists()) { logger.info("successful transfer!"); file.transferto(transferfile); else logger.info("could not create file @ " + filename);
i left out catch blocks , other logging transferfile
object created not exist @ location.
how can create file @ specified location?
- check added enctype='multipart/form-data' in form tag.
check define in configuration file spring.xml
<beans:bean id="multipartresolver" class="org.springframework.web.multipart.commons.commonsmultipartresolver"> <!-- 1 of properties available; maximum file size in bytes --> <beans:property name="maxuploadsize" value="100000000" /> </beans:bean>
2.check name atribute of file tag , use same in controller method handleupload.
3.check whether file created or not @ specified location in transfering file user i.e. check transferfile creates file or not @ destination.
Comments
Post a Comment