I have a jsp with this code snippet in it.
<form name="AudioFileConversionForm" enctype="multipart/form-data" method="post" >
Choose File: <input type="file" id="audioFile" name="audioFile"><br>
<input type="submit" value="upload">
</form>
This is my controller in spring.
public String convertFile(HttpServletRequest request, HttpSession session) {
String audioFile = request.getParameter("audioFile");
System.out.println(request.getParameter("audioFile"));
System.out.println("Audio File Conversion Successful");
}
I am unable to retrieve the name of the file, it shows null.
I know that I can retrieve the name using JQuery or javascript, but I don’t want to use them both. I want to do it using pure java.
Can anyone please help me?
When you upload the file,
requestis instance oforg.springframework.web.multipart.MultipartHttpServletRequest. So you can cast it in your methodconvertFile(). See below :—> To get file name you can get it as :
To make file upload work, you need to make sure you are creating multipart resolver bean as below :
Reference : Spring documentation