Skip to content

Commit 3c8dfd2

Browse files
committed
[bugfix] Do not creat the file before calling Part#write
1 parent 0f699ea commit 3c8dfd2

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

exist-core/src/main/java/org/exist/http/servlets/HttpRequestWrapper.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,16 @@
6161
public class HttpRequestWrapper implements RequestWrapper {
6262

6363
private static final Logger LOG = LogManager.getLogger(HttpRequestWrapper.class);
64-
64+
65+
private static final Path TMP_DIR;
66+
static {
67+
try {
68+
TMP_DIR = Files.createTempDirectory("");
69+
} catch (final IOException e) {
70+
throw new RuntimeException("Unable to create temporary directory for HttpRequestWrapper", e);
71+
}
72+
}
73+
6574
private final HttpServletRequest servletRequest;
6675
@Nullable private final String formEncoding;
6776
@Nullable private String containerEncoding;
@@ -545,13 +554,19 @@ public List<Path> getFileUploadParam(final String name) {
545554

546555
if (temporaryUploadedFilePath == null) {
547556
try {
548-
temporaryUploadedFilePath = Files.createTempFile(null, null);
557+
final String tmpFilename = UUID.randomUUID().toString() + ".tmp";
558+
559+
temporaryUploadedFilePath = TMP_DIR.resolve(tmpFilename);
549560
part.write(temporaryUploadedFilePath.toAbsolutePath().toString());
550561
} catch (final IOException e) {
551562
LOG.warn(e);
552563
continue;
553564
}
554565

566+
if (temporaryUploadedFilesPathCache == null) {
567+
temporaryUploadedFilesPathCache = new HashMap<>();
568+
}
569+
555570
temporaryUploadedFilesPathCache.put(part, temporaryUploadedFilePath);
556571
}
557572

0 commit comments

Comments
 (0)