I'm running the following Code, mostly copied from
the Demo for the MultiPart Parser from Servlets.com
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
PrintWriter out = response.getWriter();
response.setContentType("text/plain");
out.println("Demo Parser Upload Servlet");
try
{
MultipartParser mp = new MultipartParser(request, 10*1024*1024); // 10MB
Part part;
while ((part = mp.readNextPart()) != null)
{
String name = part.getName();
if (part.isParam())
{
// it's a parameter part
ParamPart paramPart = (ParamPart) part;
String value = paramPart.getStringValue();
out.println("param; name=" + name + ", value=" + value);
}//end part section
else if (part.isFile())
{
// it's a file part
FilePart filePart = (FilePart) part;
String fileName = filePart.getFileName();
out.println("Reading file: " + fileName);
if (fileName != null)
{
// the part actually contained a file
long size = filePart.writeTo(new File (path + fileName));
out.println("file; name=" + name + "; filename=" + fileName +
", content type=" + filePart.getContentType() + " size=" + size);
}
else
{
// the field did not contain a file
out.println("file; name=" + name + "; EMPTY");
}
out.flush();
}//end file section
}//end while loop
}//end try
catch (Exception e)
{
e.printStackTrace(out);
}
}//end method
I get the following output if I try to upload any file over about 7 KiloBytes
Demo Parser Upload Servlet
param; name=requesttype, value=addpicture
param; name=category, value=monte
param; name=password, value=admin
param; name=title, value=A picture
param; name=caption, value=This is a picture
Reading file: cheryse1.jpg
file; name=file; filename=cheryse1.jpg, content type=image/pjpeg size=7609
param; name=category, value=monte
param; name=password, value=admin
param; name=title, value=A picture
param; name=caption, value=This is a picture
Reading file: cheryse1.jpg
java.io.IOException: unexpected end of part
at PartInputStream.fill(PartInputStream.java:87)
at PartInputStream.read(PartInputStream.java:153)
at java.io.FilterInputStream.read(FilterInputStream.java:97)
at FilePart.write(FilePart.java:157)
at FilePart.writeTo(FilePart.java:116)
at DemoParserUploadServlet.doPost(DemoParserUploadServlet.java:52)
at javax.servlet.http.HttpServlet.service(HttpServlet.java)
at javax.servlet.http.HttpServlet.service(HttpServlet.java)
at
org.apache.tomcat.facade.ServletHandler.doService(ServletHandler.java:500)
at org.apache.tomcat.core.Handler.invoke(Handler.java:322)
at org.apache.tomcat.core.Handler.service(Handler.java:235)
at
org.apache.tomcat.facade.ServletHandler.service(ServletHandler.java:448)
at
org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:918)
at
org.apache.tomcat.core.ContextManager.service(ContextManager.java:831)
at
org.apache.tomcat.modules.server.Ajp13Interceptor.processConnection(Ajp13Interceptor.java:167)
at
org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:478)
at
org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:517)
at java.lang.Thread.run(Thread.java:479)
If I upload a very larger file, say 50K, I get several sections like this
before the
Exception is thrown. It appears that the program is reading the stream untill
it
reads 7609 Bytes of the file section, then looping back to the beginning, and
starting
all over again, but then when it gets to the file section again, it starts
where it
ended previously, and reads another section of the file stream as one file. I
think
that there is something wrong with the server that I'm running this Servlet
on. Do
any of you know what might be wrong with the server, or what kind of questions
I could
ask my technical support people? Jason, have you ever seen a MultiPartParser
produce
this kind of output??
--Monte Glenn Gardner
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html