diff --git a/spring-web/src/main/java/org/springframework/http/codec/multipart/PartGenerator.java b/spring-web/src/main/java/org/springframework/http/codec/multipart/PartGenerator.java index 39aa9149faa..3e684a47fb2 100644 --- a/spring-web/src/main/java/org/springframework/http/codec/multipart/PartGenerator.java +++ b/spring-web/src/main/java/org/springframework/http/codec/multipart/PartGenerator.java @@ -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 { 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);