Skip to content

Commit 0e5cd24

Browse files
committed
Fixes #4542 - Add ability to override upload location
1 parent 758d39f commit 0e5cd24

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

extension/fileupload/src/main/java/cloud/piranha/extension/fileupload/FileUploadMultiPartInitializer.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,10 @@
4444
* </p>
4545
*
4646
* <ol>
47-
* <li>Sets the MultiPartManager to an instance of FileUploadMultiPartManager.</li>
48-
* <li>Adds the JakartaFileCleaner listener that cleans up the temporary files.</li>
47+
* <li>Sets the MultiPartManager to an instance of
48+
* FileUploadMultiPartManager.</li>
49+
* <li>Adds the JakartaFileCleaner listener that cleans up the temporary
50+
* files.</li>
4951
* </ol>
5052
*
5153
* @author Manfred Riem (mriem@manorrock.com)
@@ -62,13 +64,17 @@ public class FileUploadMultiPartInitializer implements ServletContainerInitializ
6264
*/
6365
public FileUploadMultiPartInitializer() {
6466
}
65-
67+
6668
@Override
6769
public void onStartup(Set<Class<?>> classes, ServletContext servletContext) throws ServletException {
6870
WebApplication webApplication = (WebApplication) servletContext;
69-
LOGGER.log(TRACE, "Setting the MultiPartManager");
71+
if (LOGGER.isLoggable(TRACE)) {
72+
LOGGER.log(TRACE, "Setting the MultiPartManager");
73+
}
7074
webApplication.getManager().setMultiPartManager(new FileUploadMultiPartManager());
71-
LOGGER.log(TRACE, "Adding the listener used to cleanup temporary files");
75+
if (LOGGER.isLoggable(TRACE)) {
76+
LOGGER.log(TRACE, "Adding the listener used to cleanup temporary files");
77+
}
7278
webApplication.addListener("org.apache.commons.fileupload2.jakarta.servlet6.JakartaFileCleaner");
7379
}
7480
}

extension/fileupload/src/main/java/cloud/piranha/extension/fileupload/FileUploadMultiPartManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ private synchronized JakartaServletFileUpload setupFileUpload(WebApplication web
156156
* If the multipart config has a location use it. If it is relative
157157
* use the TEMPDIR as the parent directory.
158158
*/
159-
if (multipartConfig.getLocation() != null && multipartConfig.getLocation().isEmpty()) {
159+
if (multipartConfig.getLocation() != null && !multipartConfig.getLocation().isEmpty()) {
160160
File location = new File(multipartConfig.getLocation());
161161
if (!location.isAbsolute()) {
162162
location = ((File) webApplication.getAttribute(TEMPDIR)).toPath().resolve(location.toPath()).toFile();

0 commit comments

Comments
 (0)