Search This Blog

Saturday, April 14, 2007

Uploading File to a Java Servlet

When the servlet becomes the URL target of a FileReference.upload() method, it seems that the uploaded file can be retrieved in the inputstream of the post request, i.e. in the inputstream of the Request in doPost() method. The problem is, there are lots of other data as well in that input stream (the actual file uploaded is in a form value called Filedata) and I don't know how to extract just the uploaded file so that I can store it in the machine where the servlet is.
getParameter("Filedata") doesn't work. Does anyone know how to get around this problem?

Check out the below URL for the solution:
http://projects.apache.org/projects/jakarta_commons_fileupload.htm

Whenever one wants to upload something, append the sessionid to the request url. Something like urlRequest=new URLRequest(_servletUrl + servicePath +";jsessionid=" + _sessionId );

No comments: