@RequestMapping("/addImageAdmin")
public String addImageAdmin(@RequestParam("fname") String fname, @RequestParam("imgupload") MultipartFile file, ModelMap model) {
if (!file.isEmpty()) {
try {
ImageUpload du = new ImageUpload();
byte[] bytes = file.getBytes();
// Creating the directory to store file
String rootPath = System.getProperty("catalina.home");
File dir = new File("Important" + File.separator);
if (!dir.exists())
dir.mkdirs();
// Create the file on server
File serverFile1 = new File(dir.getAbsolutePath() + File.separator);
System.out.println("Before Stream");
BufferedOutputStream stream1 = new BufferedOutputStream(new FileOutputStream(serverFile1));
System.out.println("After Stream");
stream1.write(bytes);
stream1.close();
du.setFname(fname);
du.setImgupload(bytes);
if (imageUploadSerImpl.saveImage(du)) {
model.addAttribute("msg", "1");
} else {
model.addAttribute("msg", "0");
}
} catch (Exception e) {
e.printStackTrace();
}
} else {
}
return "add/photogal";
}
由于没有创建BufferedOutputStream的对象,保存方法没有被调用..请建议。