I have been trying to make a file upload for my spring boot project. I am currently following this tutorial from Baeldung: https://www.baeldung.com/spring-file-upload
However, I reached some problems. I have put this within my pom.xml
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>2.1.8.RELEASE</version>
</dependency>
and this within my application.properties
spring.servlet.multipart.max-file-size=128KB
spring.servlet.multipart.max-request-size=128KB
spring.servlet.multipart.enabled=true
spring.servlet.multipart.location=${java.io.tmpdir}
for my project, I only need uploading a file so I put this as my form in rekonsiliasi.html
<form method="POST" action="/spring-mvc-xml/uploadFile" enctype="multipart/form-data">
<table>
<tr>
<td><form:label path="file">Select a file to upload</form:label></td>
<td><input type="file" name="file" /></td>
</tr>
<tr>
<td><input type="submit" value="Submit" /></td>
</tr>
</table>
</form>
<h2>Submitted File</h2>
<table>
<tr>
<td>OriginalFileName:</td>
<td>${file.originalFilename}</td>
</tr>
<tr>
<td>Type:</td>
<td>${file.contentType}</td>
</tr>
</table>
and I add this into my RekonsiliasiController
@RequestMapping(value = "/uploadFile", method = RequestMethod.POST)
public String submit(@RequestParam("file") MultipartFile file, ModelMap modelMap) {
modelMap.addAttribute("file", file);
return "rekonsiliasi";
}
However, when I run it I leads me into 405 error with the message as following.
org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'GET' not supported
I tried to look it up on how to fix this and I found this: Why SpringMVC Request method 'GET' not supported?
So I tried to change all POST into GET and I received 500 error with this as the message
org.springframework.web.multipart.MultipartException: Current request is not a multipart request
Where did I go wrong?