TheOne
TheOne

Reputation: 31

How to set maxUploadSize for each file in case of multiple file uploads using CommonsMultipartResolver?

I have a requirement to support multiple file upload in one request. The user can select any number of files and upload them to the server. I would like limit each of those files not to exceed 10MB. I wrote the below code, but it limits the total size of all files combined to be less than 10MB, but I want to limit 10MB per file and total there could be any number of files. I am using spring web mvc 3.0

<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
    <!-- 10 megs is 10485760 bytes.-->
    <property name="maxUploadSize" value="10486784"/>
</bean>

Any ideas?

Upvotes: 1

Views: 1822

Answers (1)

Sazzadur Rahaman
Sazzadur Rahaman

Reputation: 7116

maxUploadSize parameter of CommonsMultipartResolver is not about to set validation on file size. Its about restricting a Multipart file upload request, so that no malicious user can upload something that overwhelms your resources to handle that request. On that case, the individual file size actually does not matters. The thing to be concerned is the total upload size. That's why CommonsMultipartResolver does not have any property to restrict individual file size.

To put restriction on individual file size, you must put a server side validation (in both cases, single file upload or multiple file upload).

Thanks and Happy coding!

Upvotes: 1

Related Questions