Search code examples
javaservletsuploadicefaces

Is there a way to upload a file using a Servlet that allows skipping the save to temporary location?


Posting this one for a friend. They have an Icefaces app that uses Icefaces's inputfile functionality but it attempts to upload the file to a temporary directory before it allows access to it. Long story short, there is no access to the temp location so copying the file (which will enventually end up in a database) is not possible. Is it possible to use a Java Servlet instead to upload the file and stream the contents to where they do have access without first having the file saved to a temporary location?


Solution

  • Yes, that's absolutely possible. The servlet's doPost() method can do whatever it wants with the input, and is designed for processing it in a streaming manner. However, wiht a bare servlet you'd have to parse the request body manually. Fortunately, Apache Commons FileUpload can do that for you.