FORM:
<form action='/ticketDataCollector/' method='post'>
<tr>
<td>
<label>Attachment</label>
</td>
<td>
<input type='file' name='attachment'>
</td>
</tr>
...
ticketDataCollector
method signature:
public ModelAndView ticketDataCollector(@ModelAttribute("ticketObject") Ticket ticketObject)
Ticket is java class:
private File attachment;
public File getAttachment(){
return attachment
}
getAttachment()
returns null
when I select a file on the HTML page.
Is there anything else that I need to do?
Configure MultiPartResolver and change content type to multipart/form-data in Your html form. See example here: https://spring.io/guides/gs/uploading-files/ And i think that spring will not autowire file in Your model. You need to do it manually..