Skip to content

Upgrade to commons-fileupload 1.5 #30416

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ configure(allprojects) { project ->
dependency "org.python:jython-standalone:2.7.1"
dependency "org.mozilla:rhino:1.7.11"

dependency "commons-fileupload:commons-fileupload:1.4"
dependency "commons-fileupload:commons-fileupload:1.5"
dependency "org.synchronoss.cloud:nio-multipart-parser:1.1.0"

dependency("org.dom4j:dom4j:2.1.3") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public static <T> Deferred<T> monoToDeferred(Mono<T> source) {
* Invoke a suspending function and converts it to {@link Mono} or
* {@link Flux}.
*/
@SuppressWarnings("deprecation")
public static Publisher<?> invokeSuspendingFunction(Method method, Object target, Object... args) {
KFunction<?> function = Objects.requireNonNull(ReflectJvmMapping.getKotlinFunction(method));
if (method.isAccessible() && !KCallablesJvm.isAccessible(function)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,16 @@ public FileUpload getFileUpload() {
return this.fileUpload;
}

/**
* Sets the maximum number of files allowed per request.
* -1 indicates no limit (the default).
* @param fileCountMax the maximum upload size allowed
* @see org.apache.commons.fileupload.FileUploadBase#setFileCountMax
*/
public void setFileCountMax(long fileCountMax) {
this.fileUpload.setFileCountMax(fileCountMax);
}

/**
* Set the maximum allowed size (in bytes) before an upload gets rejected.
* -1 indicates no limit (the default).
Expand All @@ -118,6 +128,7 @@ public void setMaxUploadSizePerFile(long maxUploadSizePerFile) {
this.fileUpload.setFileSizeMax(maxUploadSizePerFile);
}


/**
* Set the maximum allowed size (in bytes) before uploads are written to disk.
* Uploaded files will still be received past this amount, but they will not be
Expand Down Expand Up @@ -232,6 +243,7 @@ protected FileUpload prepareFileUpload(@Nullable String encoding) {
actualFileUpload = newFileUpload(getFileItemFactory());
actualFileUpload.setSizeMax(fileUpload.getSizeMax());
actualFileUpload.setFileSizeMax(fileUpload.getFileSizeMax());
actualFileUpload.setFileCountMax(fileUpload.getFileCountMax());
actualFileUpload.setHeaderEncoding(encoding);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;

import org.apache.commons.fileupload.FileCountLimitExceededException;
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.FileItemFactory;
import org.apache.commons.fileupload.FileUpload;
Expand Down Expand Up @@ -198,6 +199,9 @@ protected MultipartParsingResult parseRequest(HttpServletRequest request) throws
catch (FileUploadBase.FileSizeLimitExceededException ex) {
throw new MaxUploadSizeExceededException(fileUpload.getFileSizeMax(), ex);
}
catch (FileCountLimitExceededException ex) {
throw new MaxUploadSizeExceededException(fileUpload.getFileCountMax(), ex);
}
catch (FileUploadException ex) {
throw new MultipartException("Failed to parse multipart servlet request", ex);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,13 +147,15 @@ private void doTestWithApplicationContext(boolean lazy) throws Exception {
wac.getServletContext().setAttribute(WebUtils.TEMP_DIR_CONTEXT_ATTRIBUTE, new File("mytemp"));
wac.refresh();
MockCommonsMultipartResolver resolver = new MockCommonsMultipartResolver();
resolver.setFileCountMax(10);
resolver.setMaxUploadSize(1000);
resolver.setMaxInMemorySize(100);
resolver.setDefaultEncoding("enc");
if (lazy) {
resolver.setResolveLazily(false);
}
resolver.setServletContext(wac.getServletContext());
assertThat(resolver.getFileUpload().getFileCountMax()).isEqualTo(10);
assertThat(resolver.getFileUpload().getSizeMax()).isEqualTo(1000);
assertThat(resolver.getFileItemFactory().getSizeThreshold()).isEqualTo(100);
assertThat(resolver.getFileUpload().getHeaderEncoding()).isEqualTo("enc");
Expand Down