In a Spring MVC hibernate app , I am selecting image from JSP and sending it to controller , but image path is getting changed because of this I am getting file not found error…
This is my jsp code :
<form name="reguserform"> <input type="file" name="userImage" id="userImage"/> </form>
here I am selecting image from D: drive D:\25986.jpeg
and below is my controller class code :
public String regUser(@RequestParam("userImage") File userImage) {
System.out.println("Image = "+ userImage);
}
// here i am getting : Image = C:\fakepath\25986.jpeg
because of this I cannot procced.
I dont know why image path is getting changed automatically. should I change the Input type for image ? could somebody help me ?
Suppose it did what you want, and suppose I use your webapp, and choose to upload an image from my
K:\Documents\JBNizetdirectory. You would thus getK:\Documents\JBNizet\someImage.jpgas argument to your method. What would it be useful for? A file path on the end-user’s machine (my machine) doesn’t represent anything meaningful on the webapp server (your machine).Read Spring MVC’s documentation to understand how you must handle file uploads.