Announcement Announcement Module
Collapse
No announcement yet.
MultipartFile trouble! Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • MultipartFile trouble!

    I just don't get it to work, cant see why!

    Invalid property 'file' of bean class [se.ud.udp.model.resource.UploadItem]: Could not instantiate property type [org.springframework.web.multipart.MultipartFile] to auto-grow nested property path: java.lang.InstantiationException: org.springframework.web.multipart.MultipartFile

    applicationContext.xml
    Code:
    ...
        <bean id="multipartResolver"   class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
    	    <property name="maxUploadSize" value="50000000"/>
    	</bean>
    
    ...
    bean:
    Code:
    public class UploadItem {
        private MultipartFile file;
        private String name;
    
    	public MultipartFile getFile() {
    		return file;
    	}
    
    	public void setFile(MultipartFile file) {
    		this.file = file;
    	}
    
    	public String getName() {
    		return name;
    	}
    
    	public void setName(String name) {
    		this.name = name;
    	}
    
    }
    Controller:
    Code:
    @Controller
    @RequestMapping(value = "/upload/*")
    @SessionAttributes("uploadItem")
    public class UploadController {
    	
    	private static final Logger log = Logger.getLogger(UploadController.class);
    	@RequestMapping(value = "create" ,method = RequestMethod.GET)
    	public String getUploadForm(Model model) {
    		model.addAttribute("uploadItem", new UploadItem());	
    		
    		return "upload/uploadForm";
    	}
    	 
    	@RequestMapping(value = "submit" , method = RequestMethod.POST)
    	public String create(@ModelAttribute(value = "uploadItem") UploadItem uploadItem, BindingResult result,Model model) {
    		return "upload/finished";
    	}
    }
    form
    HTML Code:
    <html>
    ****<head>
    ********<META http-equiv="Content-Type" content="text/html;charset=UTF-8">
    ********<title>Upload Example</title>
    ****</head>
    ****<body><!--  commandName="sPosition" -->
    		PELLE: ${uploadItem.name}
    		<form:form commandName="uploadItem" enctype="multipart/form-data" action="/upload/submit" method="post">
    			<form:label path="file">File:</form:label>
    			<input type="file" name="file" />
    			<form:errors path="file" />
    			<br class="clear-both"/>
    			<input type="submit" class="submit" value="Upload"/>
    ********</form:form>
    ****</body>
    </html>
    can anyone see why?

  • #2
    Were you able to solve this issue? I am having the same trouble.

    Comment


    • #3
      Nevermind. The problem is that the CommonsMultipartResolver is made for CommonsMultipartFile. It would be nice to use MultipartFile instead.
      Originally posted by fic View Post
      Were you able to solve this issue? I am having the same trouble.

      Comment

      Working...
      X