From 647669e6c2620aced65857cf0b5b2785d8489c8f Mon Sep 17 00:00:00 2001 From: Adam Retter Date: Thu, 29 Sep 2022 21:45:53 +0200 Subject: [PATCH] [bugfix] Do not create the file before calling Part#write --- .../http/servlets/HttpRequestWrapper.java | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/exist-core/src/main/java/org/exist/http/servlets/HttpRequestWrapper.java b/exist-core/src/main/java/org/exist/http/servlets/HttpRequestWrapper.java index 6c209db9d2e..795cb4ccbd8 100644 --- a/exist-core/src/main/java/org/exist/http/servlets/HttpRequestWrapper.java +++ b/exist-core/src/main/java/org/exist/http/servlets/HttpRequestWrapper.java @@ -61,7 +61,16 @@ public class HttpRequestWrapper implements RequestWrapper { private static final Logger LOG = LogManager.getLogger(HttpRequestWrapper.class); - + + private static final Path TMP_DIR; + static { + try { + TMP_DIR = Files.createTempDirectory(""); + } catch (final IOException e) { + throw new RuntimeException("Unable to create temporary directory for HttpRequestWrapper", e); + } + } + private final HttpServletRequest servletRequest; @Nullable private final String formEncoding; @Nullable private String containerEncoding; @@ -545,13 +554,19 @@ public List getFileUploadParam(final String name) { if (temporaryUploadedFilePath == null) { try { - temporaryUploadedFilePath = Files.createTempFile(null, null); + final String tmpFilename = UUID.randomUUID().toString() + ".tmp"; + + temporaryUploadedFilePath = TMP_DIR.resolve(tmpFilename); part.write(temporaryUploadedFilePath.toAbsolutePath().toString()); } catch (final IOException e) { LOG.warn(e); continue; } + if (temporaryUploadedFilesPathCache == null) { + temporaryUploadedFilesPathCache = new HashMap<>(); + } + temporaryUploadedFilesPathCache.put(part, temporaryUploadedFilePath); }