I'm trying to implement file upload functionality in a Spring application.
Currently, I am using the multiple
attribute of HTML5 forms to send multiple files to the server. The files are htting the controller, but I am having issues transferring them to the 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());
for (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 at " + fileName);
I left out the catch blocks and other logging but the transferFile
object is created but it does not exist at the location.
How can I create the file at the specified location?