You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Stefan Groschupf <sg...@media-style.com> on 2004/08/23 23:23:45 UTC
getParameter ... called after reading... ServletInputStream
Hi,
I have trouble using the file upload.
Small uploads working but with an error message
One of the getParameter family of methods called after reading from the
ServletInputStream. Not merging post parameters.>
In case i try bigger uploads I got this exception:
Failed to parse multipart request:
org.apache.commons.fileupload.FileUploadException: Processing of
multipart/form-data request failed. EOF after reading only: '284672'
of: '16730758' promised bytes, out of which at least: '3280' were
already buffered
at
org.apache.commons.fileupload.FileUploadBase.parseRequest(FileUploadBase
.java:429)
at
org.apache.struts.upload.CommonsMultipartRequestHandler.handleRequest(Co
mmonsMultipartRequestHandler.java:233)
at
org.apache.struts.util.RequestUtils.populate(RequestUtils.java:1209)
at
org.apache.struts.action.RequestProcessor.processPopulate(RequestProcess
or.java:821)
at
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:
254)
at
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
I found only one posting that where the responder suggest do not use
any getParameter call after readting the formFile.getInputStream.
I do not call such method after getting the input stream. May someone
can give me a hint what I may doing wrong?
I figure out that all people had this problem was using weblogic, is it
may a weblogic bug?
Thanks you!
Stefan
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request,
HttpServletResponse response) {
AbstractFileForm abstractFileForm = (AbstractFileForm) form;
try {
System.out.println("start upload...");
if (abstractFileForm.getFormFile() != null) {
FormFile formFile = abstractFileForm.getFormFile();
String fileName = formFile.getFileName();
InputStream stream = formFile.getInputStream();
String tempFolder =
System.getProperty("java.io.tmpdir") + File.separator +
System.currentTimeMillis();
new File(tempFolder).mkdir();
String tempFilePath = tempFolder + File.separator +
fileName;
abstractFileForm.addFileHolder(new FileHolder(fileName,
tempFilePath));
OutputStream bos = new FileOutputStream(tempFilePath);
int bytesRead = 0;
byte[] buffer = new byte[8192];
while ((bytesRead = stream.read(buffer, 0, 8192)) !=
-1) {
bos.write(buffer, 0, bytesRead);
}
System.out.println("written to disk...");
bos.close();
stream.close();
formFile.destroy();
}
} catch (Exception e) {
System.err.println("Action error:" + e.toString());
ActionErrors errors = new ActionErrors();
ActionError error = new ActionError(e.toString());
errors.add(ActionErrors.GLOBAL_ERROR, error);
saveErrors(request, errors);
return (mapping.findForward("error"));
}
return mapping.findForward("success");
}
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org