Recreate file storage directory when removed in DefaultPartHttpMessageReader
Some operating systems delete temp files not just when booting up, but also during operation. This commit makes sure that the DefaultPartHttpMessageReader recreates the directory used to store files in, if it's not there. Closes gh-26790
This commit is contained in:
parent
4e42b5dfbc
commit
327e761536
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -20,6 +20,7 @@ import java.io.IOException;
|
|||
import java.io.UncheckedIOException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.channels.WritableByteChannel;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.StandardOpenOption;
|
||||
|
@ -53,7 +54,7 @@ import org.springframework.util.FastByteArrayOutputStream;
|
|||
|
||||
/**
|
||||
* Subscribes to a token stream (i.e. the result of
|
||||
* {@link MultipartParser#parse(Flux, byte[], int)}, and produces a flux of {@link Part} objects.
|
||||
* {@link MultipartParser#parse(Flux, byte[], int, Charset)}, and produces a flux of {@link Part} objects.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
* @since 5.3
|
||||
|
@ -577,6 +578,9 @@ final class PartGenerator extends BaseSubscriber<MultipartParser.Token> {
|
|||
|
||||
private WritingFileState createFileState(Path directory) {
|
||||
try {
|
||||
if (!Files.exists(directory)) {
|
||||
Files.createDirectory(directory);
|
||||
}
|
||||
Path tempFile = Files.createTempFile(directory, null, ".multipart");
|
||||
if (logger.isTraceEnabled()) {
|
||||
logger.trace("Storing multipart data in file " + tempFile);
|
||||
|
|
Loading…
Reference in New Issue