我下面的代码只是将数组中的第一个文件上传到路径位置。谁能看到我的服务器端控制器出了什么问题:
private static String UPLOADED_FOLDER = "C://temp//";
@RequestMapping(value = { "/fileUpload" }, method = RequestMethod.POST)
@ResponseBody
public String uploadFile( @RequestParam("number") String number, @RequestParam("files[]") MultipartFile[] files, MultipartHttpServletRequest req, HttpServletResponse res)
{
for (MultipartFile file : files) {
try {
File directory = new File(UPLOADED_FOLDER + number);
logger.info(directory.toString());
if (! directory.exists()){
directory.mkdir();
logger.info("directory created");
}
byte[] bytes = file.getBytes();
logger.info(bytes.toString());
Path path = Paths.get(UPLOADED_FOLDER + number + "//" + file.getOriginalFilename());
logger.info(path.toString());
Files.write(path, bytes);
logger.info("You have successfully uploaded '" + file.getOriginalFilename() + "'");
return("File Uploaded");
} catch (Exception e) {
res.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
logger.error("Failed to upload file '" + file.getOriginalFilename() + "'", e);
return("File Not Uploaded");
}
}
return "redirect:/fileUpload";
}
}