-->

limiting to 2 Mb

2020-07-30 06:10发布

问题:

I'm having some issues with fileUpload. It's not firing the fileUploadListener when the file is > 2 Mb.

The component:

<p:fileUpload id="upload" required="true"
fileUploadListener="#{myBean.handleFileUpload}"
fileLimit="1"
requiredMessage="A file is required"
fileLimitMessage="One file only"
invalidFileMessage="Invalid file"
cancelLabel="Cancel" label="Choose"
allowTypes="/(\.|\/)(gif|jpe?g|png)$/" />

Enviroment: JSF 2.2.3, Primefaces 4.0, Tomcat 7

Might it be some "filter" configuration problem?

@EDIT: More info. Same problem with mode="simple".

回答1:

Tomcat has a default maximum POST size of 2MB which is configurable in the HTTP <Connector> configuration in its /conf/server.xml. Here's an extract from the documentation:

maxPostSize

The maximum size in bytes of the POST which will be handled by the container FORM URL parameter parsing. The limit can be disabled by setting this attribute to a value less than or equal to 0. If not specified, this attribute is set to 2097152 (2 megabytes).

Thus, if you want to disable it, do so:

<Connector ... maxPostSize="-1">

(0 can also, but the -1 is more self-documenting as to "allow every size")