Skip to content

Commit

Permalink
[bugfix] Do not create the file before calling Part#write
Browse files Browse the repository at this point in the history
  • Loading branch information
adamretter committed Nov 29, 2024
1 parent 1804e87 commit 647669e
Showing 1 changed file with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -545,13 +554,19 @@ public List<Path> 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);
}

Expand Down

0 comments on commit 647669e

Please sign in to comment.