Spring MVC

I am Trying To Upload image and save it but i got error Code :
@PostMapping("/registration")
public String registration( @Valid @ModelAttribute("finderUserPojo") MovieFinderUserPojo finderUserPojo , BindingResult bindingResult , HttpSession httpSession , @RequestParam("image") MultipartFile image , Model model) {

if(bindingResult.hasErrors()) {
System.out.println(bindingResult.getErrorCount());
return "register";
}

try {
String email = finderUserPojo.getEmail();

MovieFinderUser existingUser = finderUserImp.findByEmail(email);

if(existingUser!=null && existingUser.getPassword().equals(finderUserPojo.getPassword())) {
return"registeredusers";
}
}
catch (EmptyResultDataAccessException e ) {
e.getMessage();
}

try {
MovieFinderUser finderUser = new MovieFinderUser(finderUserPojo.getName() , finderUserPojo.getEmail() , finderUserPojo.getPassword() , image.getBytes());
System.out.println("Image name: " + image.getOriginalFilename());

httpSession.setAttribute("User", finderUser);
finderService.addUser(finderUser);
System.out.println(image.getBytes());
}
catch (Exception e) {
e.printStackTrace();
}
return "userregistered" ;
}
@PostMapping("/registration")
public String registration( @Valid @ModelAttribute("finderUserPojo") MovieFinderUserPojo finderUserPojo , BindingResult bindingResult , HttpSession httpSession , @RequestParam("image") MultipartFile image , Model model) {

if(bindingResult.hasErrors()) {
System.out.println(bindingResult.getErrorCount());
return "register";
}

try {
String email = finderUserPojo.getEmail();

MovieFinderUser existingUser = finderUserImp.findByEmail(email);

if(existingUser!=null && existingUser.getPassword().equals(finderUserPojo.getPassword())) {
return"registeredusers";
}
}
catch (EmptyResultDataAccessException e ) {
e.getMessage();
}

try {
MovieFinderUser finderUser = new MovieFinderUser(finderUserPojo.getName() , finderUserPojo.getEmail() , finderUserPojo.getPassword() , image.getBytes());
System.out.println("Image name: " + image.getOriginalFilename());

httpSession.setAttribute("User", finderUser);
finderService.addUser(finderUser);
System.out.println(image.getBytes());
}
catch (Exception e) {
e.printStackTrace();
}
return "userregistered" ;
}
Error :
Required request part 'image' is not present

Description The server cannot or will not process the request due to something that is perceived to be a client error (e.g., malformed request syntax, invalid request message framing, or deceptive request routing).
Required request part 'image' is not present

Description The server cannot or will not process the request due to something that is perceived to be a client error (e.g., malformed request syntax, invalid request message framing, or deceptive request routing).
Can someone help me please
21 Replies
JavaBot
JavaBot6mo ago
This post has been reserved for your question.
Hey @Danix! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
straightface
straightface6mo ago
as the error suggests image is not present fire up chrome devtools see if your request contains image
Danix
DanixOP6mo ago
How to do that @straightface
straightface
straightface6mo ago
ctrl shift i go to network tab
Danix
DanixOP6mo ago
Yehh I know but after that what ? Yehhh Then
straightface
straightface6mo ago
find POST /registration request
Danix
DanixOP6mo ago
No description
straightface
straightface6mo ago
go back and submit again
Danix
DanixOP6mo ago
No description
Danix
DanixOP6mo ago
this is what i got @straightface
<form:form modelAttribute = "finderUserPojo" id="registrationForm" action="registration" method="post" enctype="multipart/form-data"> >
<div class="form-group">
<form:label path = "name" for="name">Full Name</label></form:label>
<form:input path = "name" type="text" id="name" name="name" placeholder="Enter your full name"></form:input>
<form:errors path = "name" cssClass="error-message">

</form:errors>
<span class="icon"><i class="fas fa-user"></i></span>
</div>
<div class="form-group">
<form:label path = "email" for="email">Email</label></form:label>
<form:input path = "email" type="email" id="email" name="email" placeholder="Enter your email"></form:input>
<form:errors path = "email" cssClass="error-message">

</form:errors>
<span class="icon"><i class="fas fa-envelope"></i></span>
</div>
<div class="form-group">
<form:label path = "password" for="password">Password</label></form:label>
<form:input path = "password" type="password" id="password" name="password" placeholder="Enter your password" ></form:input>
<form:errors path = "password" cssClass="error-message">

</form:errors>
<span class="icon"><i class="fas fa-lock"></i></span>
</div>

<div class="form-group">
<form:label path="image" for="image" >Upload Image</form:label>
<form:input path = "image" type="file" id="image" name="image"/>
</div>

<div class="form-group">
<button type="submit">Sign Up</button>
</div>
</form:form>
<div class="signup-link">
Already have an account? <a href="login">Log In</a>
</div>
</div>
<form:form modelAttribute = "finderUserPojo" id="registrationForm" action="registration" method="post" enctype="multipart/form-data"> >
<div class="form-group">
<form:label path = "name" for="name">Full Name</label></form:label>
<form:input path = "name" type="text" id="name" name="name" placeholder="Enter your full name"></form:input>
<form:errors path = "name" cssClass="error-message">

</form:errors>
<span class="icon"><i class="fas fa-user"></i></span>
</div>
<div class="form-group">
<form:label path = "email" for="email">Email</label></form:label>
<form:input path = "email" type="email" id="email" name="email" placeholder="Enter your email"></form:input>
<form:errors path = "email" cssClass="error-message">

</form:errors>
<span class="icon"><i class="fas fa-envelope"></i></span>
</div>
<div class="form-group">
<form:label path = "password" for="password">Password</label></form:label>
<form:input path = "password" type="password" id="password" name="password" placeholder="Enter your password" ></form:input>
<form:errors path = "password" cssClass="error-message">

</form:errors>
<span class="icon"><i class="fas fa-lock"></i></span>
</div>

<div class="form-group">
<form:label path="image" for="image" >Upload Image</form:label>
<form:input path = "image" type="file" id="image" name="image"/>
</div>

<div class="form-group">
<button type="submit">Sign Up</button>
</div>
</form:form>
<div class="signup-link">
Already have an account? <a href="login">Log In</a>
</div>
</div>
This is the jsp
straightface
straightface6mo ago
is your devtools open when you are submitting?\
Danix
DanixOP6mo ago
Yehh
straightface
straightface6mo ago
then it shold be showing up in network
Danix
DanixOP6mo ago
I sended u the image
straightface
straightface6mo ago
No description
straightface
straightface6mo ago
something like this
Danix
DanixOP6mo ago
No I don't get that options
straightface
straightface6mo ago
can you share your screen in Talk01 dont connect voice tho we will chat here instead
Danix
DanixOP6mo ago
Yehh sure
straightface
straightface6mo ago
paste error here @Danix
JavaBot
JavaBot6mo ago
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.
Want results from more Discord servers?
Add your server