Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8588117
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T22:44:03+00:00 2026-06-11T22:44:03+00:00

How to persist Image in Database Using Spring MVC3 controller: public String postAdd(@ModelAttribute(employeeAttribute) @Valid

  • 0

How to persist Image in Database Using Spring MVC3

controller:

public String postAdd(@ModelAttribute("employeeAttribute") @Valid Employee  employee,   BindingResult result,@RequestParam("file") MultipartFile   file) throws Exception{

       byte[] bFile=null;

       System.out.println("File Name......"+file.getName());

        if (!file.isEmpty()) {

          bFile = new byte[(int) file.getSize()];
        FileInputStream fileInputStream = new FileInputStream(file.getOriginalFilename());         
             fileInputStream.read(bFile);
             fileInputStream.close();
            }


              employee.setImage(bFile);

     employeeServiceImpl.add(employee);

}

Jsp Page:

     <c:url var="saveEmp" value="/manam/mobee/employee/add"/>
       <form:form modelAttribute="employeeAttribute" method="POST" action="${saveEmp}"          enctype="multipart/form-data" >
      <form:label path="image">Image</form:label>
       <input type="file" name="file" id="file"></input>

here Iam sending the C:\Users\Public\Pictures\Sample Pictures\Desert Landscape.jpg file but
FileInputStream it will take only Landscape.jpg .
please suggest how to set full file path for FileInputStream.

Here I am getting java.io.FileNotFoundException: Forest.jpg (The system cannot find the file specified) Exception.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T22:44:04+00:00Added an answer on June 11, 2026 at 10:44 pm

    The original file name is the name of the file on the end-user’s machine. Your Spring MVC application runs on your server machine. You can’t use the original file name, hope to find the absolute file name on the end-user machine, and even less try to read the file using this name.

    To get the contents of the uploaded file, use MultipartFile.getBytes() or MultipartFile.getInputStream().

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to persist an Image in my Article Entity. Is this possible with
I am trying to persist an object into the database. This operation should touch
I am trying to persist an Entity with a @Lob annotated String field. The
I use NSData to persist an image in my application. I save the image
CONTROLLER class ImagesController extends AppController { var $name = 'Images'; var $uses = array('Image','Person');
The image property is not getting updated. I am using this.user.setImage(a) to set the
I'm using App Engine's high performance image serving on my site, and I'm able
We need to add a text watermark to an image, using something like imagegettftext.
From the image above you can see a column in the MySQL database (table
I need to insert an image in access database that has a column of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.