commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Martin Cooper" <mart...@apache.org>
Subject Re: [FileUpload] FileUpload limit ? It's only a question
Date Thu, 22 Apr 2004 18:23:51 GMT
I can see two fairly obvious problems with the way you are configuring
FileUpload.

1) You are limiting the total request size to 8MB, regardless of how many
files are uploaded. (setSizeMax()) If you upload a lot of smaller files,
you'll still break that 8MB limit, and an exception will be thrown.

2) You are keeping all of the uploaded files in memory, and preventing
FileUpload from writing anything to disk. (setSizeThreshold()) Depending on
how much memory your VM has available, this could cause you problems as
well. Unless you have a pressing need to keep everything in memory, I would
recommend setting the threshold (much) lower, to allow files to be written
to disk.

--
Martin Cooper


"Florian Kiebel" <florian.kiebel@matamore.com> wrote in message
news:20040422173439.22BC3F94D5@postfix4-1.free.fr...
Hello

You are right, of course, I didn't want to spend all my stuff but it's the
only thing I can do in order to have a solution.

Ok I have a HTML form: chargement.html with this form:

<form name="test_upload" method="post" action="upload.jsp"
enctype="multipart/form-data" >
  <input type="file" name="fileName1" value="" ><br>
  <input type="file" name="fileName2" value="" ><br>
  <input type="file" name="fileName3" value="" ><br>
  <input type="file" name="fileName4" value="" ><br>
  <input type="submit" name="Submit" value="Envoyer" >
</form>

And a jsp page which receive the data:

String fileNameInServer;
int  yourMaxMemorySize = 1024 * 1024 * 8;
int  yourMaxRequestSize = 1024 * 1024 * 8;

String yourTempDirectory = "c:\\temp\\";

fileNameInServer="";
System.out.println("initialisation...");
DiskFileUpload upload = new DiskFileUpload();


// Set upload parameters
upload.setSizeThreshold(yourMaxMemorySize);
upload.setSizeMax(yourMaxRequestSize);
upload.setRepositoryPath(yourTempDirectory);

// Parse the request

System.out.println("Préparation au parsing de la requête...");
// Parse the request
List items = null;
try {
System.out.print("Parsing...");
items = upload.parseRequest(request,
        yourMaxMemorySize, yourMaxRequestSize, yourTempDirectory);
    System.out.println(" Effectué");
} catch (FileUploadException e) {
//e.printStackTrace();
//throw new IOException("could not be uploaded");
out.write("le fichier ne peut pas être chargé : fichier trop
volumineux<BR>");
out.write("taille maximale autorisée : " + yourMaxRequestSize /
(1024 * 1024) + "Mo");
return;
}
catch (Exception e)
{
System.out.println("Erreur parsing: " + e.getMessage());
System.out.println("Erreur probable: " +e.getCause());
}
System.out.println("Processing des pièces attachées...");

// Process the uploaded items
Iterator iter = items.iterator();
int i = 0;
while (iter.hasNext())
{
i++;
System.out.println("itération= " + i);
    FileItem item = (FileItem) iter.next();

    if (item.isFormField()) {
    System.out.println("FormField");
        //processFormField(item);
    }
    else
    {
    if (!item.getName().equals(""))
    {
    System.out.println("Nouveau fichier");
    String fieldName = item.getFieldName();
    String pathfileName = item.getName();
    String fileName ;
    String contentType = item.getContentType();
    boolean isInMemory = item.isInMemory();
    long sizeInBytes = item.getSize();

    String[] parts = pathfileName.split("[\\\\/]");
    fileName = parts[parts.length-1];

    out.write("fieldName=" + fieldName + "<BR>");
    out.write("fileName=" + fileName + "<BR>");
    out.write("pathfileName=" + pathfileName + "<BR>");
    out.write("contentType =" + contentType + "<BR>");
    out.write("isInMemory =" + isInMemory + "<BR>");
    out.write("sizeInBytes =" + sizeInBytes + "<BR>");

    InputStream uploadedStream ;

    if (bWriteIntoDatabase) {
    uploadedStream = item.getInputStream();

    pjprop.insertFile(fileName, uploadedStream);

    uploadedStream.close();
}
else
{
    File uploadedFile = new File(yourTempDirectory +
fileName);
    item.write(uploadedFile );
    item.delete();
pjprop.insertFile(item.getName(),
item.getInputStream());
}
}
else
{
System.out.println("item.getName() = vide");
}
    }
}
Pjprop is an object which permits to take an InputStream and to load it in a
MySQL database

Ok and now this the best. Here are my exceptions and errors:
Rapport d''exception

message

description Le serveur a recontrer une erreur interne () qui l'a empèché de
satisfaire la requête.

exception

org.apache.jasper.JasperException
at
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:2
54)
at
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Application
FilterChain.java:247)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterCh
ain.java:193)
at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.ja
va:256)
at
org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invok
eNext(StandardPipeline.java:643)
at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at
org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.ja
va:191)
at
org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invok
eNext(StandardPipeline.java:643)
at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at
org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at
org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2415)
at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180
)
at
org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invok
eNext(StandardPipeline.java:643)
at
org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.
java:171)
at
org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invok
eNext(StandardPipeline.java:641)
at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:172
)
at
org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invok
eNext(StandardPipeline.java:641)
at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at
org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java
:174)
at
org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invok
eNext(StandardPipeline.java:643)
at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at
org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at
org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:223)
at
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:594)
at
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConne
ction(Http11Protocol.java:392)
at
org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:565)
at
org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.jav
a:619)
at java.lang.Thread.run(Thread.java:534)


cause mère

javax.servlet.ServletException
at
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImp
l.java:536)
at org.apache.jsp.upload_jsp._jspService(upload_jsp.java:268)
at
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:137)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:2
10)
at
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Application
FilterChain.java:247)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterCh
ain.java:193)
at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.ja
va:256)
at
org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invok
eNext(StandardPipeline.java:643)
at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at
org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.ja
va:191)
at
org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invok
eNext(StandardPipeline.java:643)
at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at
org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at
org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2415)
at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180
)
at
org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invok
eNext(StandardPipeline.java:643)
at
org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.
java:171)
at
org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invok
eNext(StandardPipeline.java:641)
at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:172
)
at
org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invok
eNext(StandardPipeline.java:641)
at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at
org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java
:174)
at
org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invok
eNext(StandardPipeline.java:643)
at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at
org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at
org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:223)
at
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:594)
at
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConne
ction(Http11Protocol.java:392)
at
org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:565)
at
org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.jav
a:619)
at java.lang.Thread.run(Thread.java:534)

It's a big mail! I hope you can help me with this! The filesize I upload
must be < 8Mo

Thanks for help

Florian Kiebel

-----Message d'origine-----
De : news [mailto:news@sea.gmane.org] De la part de Martin Cooper
Envoyé : jeudi 22 avril 2004 18:35
À : commons-user@jakarta.apache.org
Objet : Re: [FileUpload] FileUpload limit ? It's only a question

Without any information on how you are configuring FileUpload, which
container you are using, how big the files are that you are trying to
upload, whether or not the size of the files makes a difference to how many
you can successfully upload, and the stack trace that you are seeing when
things go wrong, we really don't have much to go on, no matter how often you
post the same question. ;-)

By the way, I recommend against using FileUpload from within a JSP page in
the first place. JSP pages are intended for text-based presentation, not
parsing of binary uploads. You should do this from within a servlet instead.

--
Martin Cooper




---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Mime
View raw message