I am uploading a file from HTML
<center><form action="pdf" method="post" enctype="multipart/form-data">
<b>Upload Certificate</b>
<input type="file" name="file"/></center>
<center> <input type="submit" /></center>
</form>
On submitting the form, pdf Servlet is called. Inside the servlet the request object is parsed and file(pdf) is read using InputStream as given in code below.
protected void doPost(HttpServletRequest paramHttpServletRequest, HttpServletResponse paramHttpServletResponse)
throws ServletException, IOException
{
try
{
List localList = new ServletFileUpload(new DiskFileItemFactory()).parseRequest(paramHttpServletRequest);
for (FileItem localFileItem : localList)
{
String str1 = localFileItem.getFieldName();
String str2 = FilenameUtils.getName(localFileItem.getName());
System.out.println("fieldname:" + str1);
System.out.println("filename:" + str2);
InputStream localInputStream = localFileItem.getInputStream();
try
{
PdfReader localPdfReader = new PdfReader(localInputStream);
paramHttpServletResponse.sendRedirect("takedetails.jsp");
}
catch (InvalidPdfException localInvalidPdfException)
{
paramHttpServletResponse.sendRedirect("upload.jsp");
}
}
}
catch (FileUploadException localFileUploadException)
{
throw new ServletException("Cannot parse multipart request.", localFileUploadException);
}
}
As you can see,I used InputStream object to check for file format as pdf.
Now I want to save this pdf file to postgresql Database. What field should i use in postgresql and how can I get the file from InputStream object to store it in database?