0

Resume uploading/downloading in java

i want to store my resumes inside mysql database and then download in my system. resume size is upto 5 mb. how to do it??

currently i i saved path in database and resume in a folder.

Chetak Bhimani
  • 459
  • 4
  • 19

1 Answers1

0

Refer ServletFileUpload() provided by the servlet Technology, the below is a piece of code demonstrating the reading of file submited by the client.

 protected void doPost(HttpServletRequest request, HttpServletResponse response) throws  ServletException, IOException {
 try {
    List<FileItem> items = new ServletFileUpload(new  DiskFileItemFactory()).parseRequest(request);
     for (FileItem item : items) {
        if (item.isFormField()) {
            // Process regular form field (input type="text|radio|checkbox|etc", select, etc).
            String fieldname = item.getFieldName();
            String fieldvalue = item.getString();
            // ... (do your job here)
        } else {
            // Process form file field (input type="file").
            String fieldname = item.getFieldName();
            String filename = FilenameUtils.getName(item.getName());
            InputStream filecontent = item.getInputStream();
            // store your file in mysql db
         }
     }
  } catch (FileUploadException e) {
     throw new ServletException("Cannot read the file", e);
  }

   // ...
  }

servlet is a forefather of jsp, therefore you can use the same method in jsp also.

Balayesu Chilakalapudi
  • 1,386
  • 3
  • 19
  • 43