Hello,

I have a following problem with the servlet code using commons.fileupload (see below).

If I try to upload a file (using form, method POST and enctype="multipart/form-data") larger than few KB, temporary file is created (size 10-40 KB, varies) but the destination file is not created. E.g. I’ve tried to upload 354 KB file, 40 KB temporary file was created on the server running and the iterator was empty (see below) . I have tested with several different files and uploaded from several different clients: results always vary and I was successful uploading only two 5 and 7 KB large files from one client (others have also failed with these files). On the local server files are uploaded correctly independent of their size, without any errors. Server is Tomcat 5.5.

//CODE BEGIN
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
...

DiskFileItemFactory factory = new DiskFileItemFactory();
File d = new File("somedir");
d.mkdir();
factory.setRepository(d);

ServletFileUpload upload = new ServletFileUpload(factory);
upload.setSizeMax(10000000);

List fileItems = null;
try {
fileItems = upload.parseRequest(request);
} catch (FileUploadException e1) {
e1.printStackTrace();
}

Iterator i = fileItems.iterator(); //Line 87
FileItem fi = (FileItem) i.next();
String fileName = fi.getName();
File f = new File(somedir+"/"+fileName);

try {
fi.write(f);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

...
} //CODE END

//LOG BEGIN

Servlet.service() for servlet UploadModel threw exception

java.lang.NullPointerException

at jsp.servlets.UploadFile.doGet(UploadModel.java:87)

at jsp.servlets.UploadFile.doPost(UploadModel.java:128)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)

at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)

at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)

at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:174)

at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)

at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)

at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)

at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:151)

at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:874)

at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)

at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)

at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)

at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689)

at java.lang.Thread.run(Thread.java:595)

//LOG END

(referring to the line 87 where Iterator is initialized).

Thanks in advance,
Regards
--
b


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to