Max size for upload...

G

gbattine

Hi guys,
i've a simple question for you.
I'm developing a jsf application that allows to user to upload a file
into a mysql table.
I'm using Jakarta project to perform upload.
Everythings go well until a maxsize is reached, after i have
error......
how can i set this maxsize?
Can i change it?
How?
Thanks....
 
M

Moiristo

gbattine said:
Hi guys,
i've a simple question for you.
I'm developing a jsf application that allows to user to upload a file
into a mysql table.
I'm using Jakarta project to perform upload.
Everythings go well until a maxsize is reached, after i have
error......
how can i set this maxsize?
Can i change it?
How?
Thanks....

If you're using the Myfaces extensions Filter (what you probably do,
because you're able to upload files), your web.xml should contain
something like this:


<filter>
<filter-name>MyFacesExtensionsFilter</filter-name>

<filter-class>org.apache.myfaces.webapp.filter.ExtensionsFilter</filter-class>
<init-param>
<param-name>maxFileSize</param-name>
<param-value>20m</param-value>
<description>Set the size limit for uploaded files.
Format: 10 - 10 bytes
10k - 10 KB
10m - 10 MB
1g - 1 GB
</description>
</init-param>
</filter>
 
G

gbattine

thanks very much,
but i've already done it...my application web.xml is bit different and
this is the filter part

<filter>
<filter-name>ExtensionsFilter</filter-name>

<filter-class>org.apache.myfaces.component.html.util.ExtensionsFilter</filter-class>
<init-param>
<param-name>uploadMaxFileSize</param-name>
<param-value>10MB</param-value>
</init-param>
<init-param>
<param-name>uploadThresholdSize</param-name>
<param-value>100k</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>ExtensionsFilter</filter-name>
<servlet-name>FacesServlet</servlet-name>
</filter-mapping>

I'm using a jsf application that upload a file into a mysql db.
The file is read from an action method and converted into an array of
byte and the array of byte is put into mysql db.
When i upload a file of 3,4 MB everythings go well, when my file became
about 6,7MB...error!This is my eclipse error,i think i've to enlarge
heap size,but how can i do it?
I use TOMCAT Server 5.0 embedded with Eclipse......
This is the error...can you help me?

12-lug-2006 10.24.01 com.sun.faces.lifecycle.InvokeApplicationPhase
execute
GRAVE: Error calling action method of component with id MyForm:_id5
javax.faces.FacesException: Error calling action method of component
with id MyForm:_id5
at
org.apache.myfaces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:74)
at javax.faces.component.UICommand.broadcast(UICommand.java:312)
at
javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:267)
at
javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:381)
at
com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:75)
at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:200)
at
com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:90)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:197)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
at
org.apache.myfaces.webapp.filter.ExtensionsFilter.doFilter(ExtensionsFilter.java:144)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:186)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
at
org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at
org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:198)
at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:152)
at
org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137)
at
org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:118)
at
org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at
org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at
org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929)
at
org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
at
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
at
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)
at
org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)
at
org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
at java.lang.Thread.run(Unknown Source)
Caused by: javax.faces.el.EvaluationException:
java.lang.OutOfMemoryError: Java heap space
at
com.sun.faces.el.MethodBindingImpl.invoke(MethodBindingImpl.java:130)
at
org.apache.myfaces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:63)
... 34 more
Caused by: java.lang.OutOfMemoryError: Java heap space


Thanks very much
 
A

Andrew T.

gbattine wrote:

(set MaxFileSize in web.xml)
..i've already done it...my application web.xml is bit different and
this is the filter part ....
....
I'm using a jsf application that upload a file into a mysql db.
The file is read from an action method and converted into an array of
byte and the array of byte is put into mysql db.
When i upload a file of 3,4 MB everythings go well, when my file became
about 6,7MB...error!This is my eclipse error,i think i've to enlarge
heap size,but how can i do it? ....
Caused by: java.lang.OutOfMemoryError: Java heap space

Yes, your analysis sounds correct. This is not a problem within
the web protocol (which is often the cause of truncated uploads),
but in the amount of memory available to the JVM on the server..

There are two strategies you might pursue to resolve it, but I am
not sure if either is suitable.

1. Write the file to disk as it is recieved, rather than store the
file contents in the JVM memory until it is completely uploaded.
2. Increase the memory size of the JVM on the server. This is
probably unnecessary (see 1.), problematic (if it is someone elses
server) and will still run out of memory (with still larger file
sizes).

HTH
Andrew T.
 
G

gbattine

Thanks Andrew...
but it's not clear for me...
what have i do?
When i upload the txt file my application convert it into an array of
byte like

byte[] data;

and later with these operations

Context envCtx = (Context) ctx.lookup("java:comp/env");
DataSource ds = (DataSource) ctx.lookup("java:comp/env/MysqlJNDI");

if (ds != null) {
Connection conn = ds.getConnection();
if (conn != null) {
PreparedStatement pst = null;
pst = conn.prepareStatement("INSERT INTO tbl(Data) VALUES (?)");
pst.setBytes(1, data);
pst.executeUpdate();
pst.close();
conn.close();
}
}

i put the array of byte into a mysql table.

What have i do to solve my problem?
Can you help me?please...
 
M

Moiristo

Andrew said:
1. Write the file to disk as it is recieved, rather than store the
file contents in the JVM memory until it is completely uploaded.

The UploadedFile class can do this automatically, I thought. It's bad
that it's so poorly documented.
2. Increase the memory size of the JVM on the server. This is
probably unnecessary (see 1.), problematic (if it is someone elses
server) and will still run out of memory (with still larger file
sizes).

Default heap size for tomcat is 32M or something. I think that is not
very much and (looking at my own projects), it's always a good idea to
increase this a little. The way it's done is different for Windows/Linux:

http://confluence.atlassian.com/pages/viewpage.action?pageId=154071
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top