This is my project structure:
as you can see I have the images folder where I need to transfer the product pictures. But the next lines of codes:
MultipartFile productImage = newProduct.getProductImage();
String rootDirectory = request.getSession().getServletContext().getRealPath("/");
if(productImage != null && !productImage.isEmpty())
{
try
{
productImage.transferTo(new File(rootDirectory + "resources\\images\\" + newProduct.getProductId() + ".png"));
}
catch(Exception ex)
{
throw new RuntimeException("Product Image Saving failed", ex);
}
}
After to add a new product the product image is uploaded to: C:\Users\PC\sts_ws\spring-java-app\module2\1\webstore\target\webstore-1.0-SNAPSHOT\resources\images
But I need the path: C:\Users\PC\sts_ws\spring-java-app\module2\1\webstore\src\main\webapp\resources\images
I dont know how to point to my desired path.
thanks for your help.
Aucun commentaire:
Enregistrer un commentaire