From ec9193473052de39006f32279d46210899621062 Mon Sep 17 00:00:00 2001 From: Rossen Stoyanchev Date: Wed, 5 Jun 2019 10:54:56 -0400 Subject: [PATCH] Use correct file options for transferTo Similar to fix applied to Synchronoss implementation in #cef98e. --- .../codec/multipart/DefaultMultipartMessageReader.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/spring-web/src/main/java/org/springframework/http/codec/multipart/DefaultMultipartMessageReader.java b/spring-web/src/main/java/org/springframework/http/codec/multipart/DefaultMultipartMessageReader.java index d24ebe7d17..ca1c3e2566 100644 --- a/spring-web/src/main/java/org/springframework/http/codec/multipart/DefaultMultipartMessageReader.java +++ b/spring-web/src/main/java/org/springframework/http/codec/multipart/DefaultMultipartMessageReader.java @@ -21,6 +21,7 @@ import java.nio.channels.AsynchronousFileChannel; import java.nio.channels.Channel; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; +import java.nio.file.OpenOption; import java.nio.file.Path; import java.nio.file.StandardOpenOption; import java.util.Collections; @@ -367,6 +368,10 @@ public class DefaultMultipartMessageReader extends LoggingCodecSupport implement private static class DefaultFilePart extends DefaultPart implements FilePart { + private static final OpenOption[] FILE_CHANNEL_OPTIONS = + {StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING, StandardOpenOption.WRITE}; + + public DefaultFilePart(HttpHeaders headers, DataBuffer body) { super(headers, body); } @@ -380,7 +385,7 @@ public class DefaultMultipartMessageReader extends LoggingCodecSupport implement @Override public Mono transferTo(Path dest) { - return Mono.using(() -> AsynchronousFileChannel.open(dest, StandardOpenOption.WRITE), + return Mono.using(() -> AsynchronousFileChannel.open(dest, FILE_CHANNEL_OPTIONS), this::writeBody, this::close); }