-
Notifications
You must be signed in to change notification settings - Fork 178
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a new limit for the number of files uploaded per request (#185)
Back port
- Loading branch information
Showing
3 changed files
with
82 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
src/main/java/org/apache/commons/fileupload/FileCountLimitExceededException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.commons.fileupload; | ||
|
||
/** | ||
* This exception is thrown if a request contains more files than the specified | ||
* limit. | ||
*/ | ||
public class FileCountLimitExceededException extends FileUploadException { | ||
|
||
private static final long serialVersionUID = 6904179610227521789L; | ||
|
||
/** | ||
* The limit that was exceeded. | ||
*/ | ||
private final long limit; | ||
|
||
/** | ||
* Creates a new instance. | ||
* | ||
* @param message The detail message | ||
* @param limit The limit that was exceeded | ||
*/ | ||
public FileCountLimitExceededException(final String message, final long limit) { | ||
super(message); | ||
this.limit = limit; | ||
} | ||
|
||
/** | ||
* Retrieves the limit that was exceeded. | ||
* | ||
* @return The limit that was exceeded by the request | ||
*/ | ||
public long getLimit() { | ||
return limit; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
e20c049
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@markt-asf Can you please cherry-pick this one into
master
? :))e20c049
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That fix has a bug. It's not checking if items are simple fields or files, so if you send more than 10 fields in the form throws the FileCountLimitExceededException.
e20c049
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The name might not be the best given the circumstances but the behaviour is as intended.
e20c049
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem is that if you submit a form (with the default specifications) with more than 9 fields, whether or not they are files, the exception is thrown.
e20c049
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How is that happening? The limit is disabled by default. Might something else be going on?
e20c049
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So... it's not file, but field?
e20c049
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. It limits fields regardless of whether it represents an uploaded file or not.
e20c049
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, thanks for the explanation
e20c049
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👋 Looks like I've reported the same here https://issues.apache.org/jira/browse/FILEUPLOAD-351
e20c049
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea @rkovarik , it's the same error.