Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I figured it out. The fakepath was a security feature in browsers. What happens though with tomcat is that the file is actually stored in a temp folder inside the tomcat folder. So i just had to play with a tomcat library, commons.fileupload, and i used that to pull the data from the file, regardless of the fakepath location.</p> <pre><code>//Handle File Upload for the attachment ServletFileUpload servletFileUpload = new ServletFileUpload(new DiskFileItemFactory()); try{ List fileItemsList = servletFileUpload.parseRequest(request); //TODO: Take datafile input from the field and pass the file name so that we can view the file name Iterator it = fileItemsList.iterator(); while (it.hasNext()){ FileItem fileItem = (FileItem)it.next(); if (fileItem.isFormField()){ /* The file item contains a simple name-value pair of a form field */ } else{ //do what you want with the file} </code></pre> <p>I then passed it through to my mail utility, changed the name of the file to the correct name to have the correct extension, and it worked. Of course, you have to encode the form as a multipart form, and you have to make the Mime Message multipart as well. But its fairly simple after all that.</p> <pre><code> MimeBodyPart textPart = new MimeBodyPart(); textPart.setContent(body, "text/html"); MimeBodyPart attachFilePart = new MimeBodyPart(); FileDataSource fds = new FileDataSource(file); attachFilePart.setDataHandler(new DataHandler(fds)); attachFilePart.setFileName(fileName); Multipart mp = new MimeMultipart(); mp.addBodyPart(textPart); mp.addBodyPart(attachFilePart); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload