无法在webapp / resources / images文件夹中上传图像

时间:2020-10-18 14:59:59

标签: spring spring-mvc

我无法使用此代码上传图片,尽管它没有显示任何错误,但同时图片也没有保存在文件夹中。

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);
    }
}

0 个答案:

没有答案
相关问题