我无法使用此代码上传图片,尽管它没有显示任何错误,但同时图片也没有保存在文件夹中。
MultipartFile productImage = product.getProductImage();
String rootDirectory = request.getSession().getServletContext().getRealPath("/");
path = Paths.get(rootDirectory + "resources/images/" + product.getProductId() + ".png");
if(productImage != null && !productImage.isEmpty()){
try {
productImage.transferTo(new File(path.toString()));
System.out.println("image edited then saved ");
} catch (Exception ex){
ex.printStackTrace();
throw new RuntimeException("Product image saving failed", ex);
}
}