diff --git a/codec-http/src/main/java/io/netty/handler/codec/http/multipart/HttpPostRequestEncoder.java b/codec-http/src/main/java/io/netty/handler/codec/http/multipart/HttpPostRequestEncoder.java index 7b352f179b..5afc6562a0 100755 --- a/codec-http/src/main/java/io/netty/handler/codec/http/multipart/HttpPostRequestEncoder.java +++ b/codec-http/src/main/java/io/netty/handler/codec/http/multipart/HttpPostRequestEncoder.java @@ -636,7 +636,7 @@ public class HttpPostRequestEncoder implements ChunkedInput { replacement.append("; ") .append(HttpHeaderValues.FILENAME) .append("=\"") - .append(fileUpload.getFilename()) + .append(currentFileUpload.getFilename()) .append('"'); } diff --git a/codec-http/src/test/java/io/netty/handler/codec/http/multipart/HttpPostRequestEncoderTest.java b/codec-http/src/test/java/io/netty/handler/codec/http/multipart/HttpPostRequestEncoderTest.java index fbaef9bf38..d711c1bf44 100755 --- a/codec-http/src/test/java/io/netty/handler/codec/http/multipart/HttpPostRequestEncoderTest.java +++ b/codec-http/src/test/java/io/netty/handler/codec/http/multipart/HttpPostRequestEncoderTest.java @@ -138,9 +138,11 @@ public class HttpPostRequestEncoderTest { HttpPostRequestEncoder encoder = new HttpPostRequestEncoder(request, true); File file1 = new File(getClass().getResource("/file-01.txt").toURI()); File file2 = new File(getClass().getResource("/file-02.txt").toURI()); + File file3 = new File(getClass().getResource("/file-03.txt").toURI()); encoder.addBodyAttribute("foo", "bar"); encoder.addBodyFileUpload("quux", file1, "text/plain", false); encoder.addBodyFileUpload("quux", file2, "text/plain", false); + encoder.addBodyFileUpload("quux", file3, "text/plain", false); // We have to query the value of these two fields before finalizing // the request, which unsets one of them. @@ -159,7 +161,7 @@ public class HttpPostRequestEncoderTest { CONTENT_TYPE + ": multipart/mixed; boundary=" + multipartMixedBoundary + "\r\n" + "\r\n" + "--" + multipartMixedBoundary + "\r\n" + - CONTENT_DISPOSITION + ": attachment; filename=\"file-02.txt\"" + "\r\n" + + CONTENT_DISPOSITION + ": attachment; filename=\"file-01.txt\"" + "\r\n" + CONTENT_LENGTH + ": " + file1.length() + "\r\n" + CONTENT_TYPE + ": text/plain" + "\r\n" + CONTENT_TRANSFER_ENCODING + ": binary" + "\r\n" + @@ -174,6 +176,14 @@ public class HttpPostRequestEncoderTest { "\r\n" + "File 02" + StringUtil.NEWLINE + "\r\n" + + "--" + multipartMixedBoundary + "\r\n" + + CONTENT_DISPOSITION + ": attachment; filename=\"file-03.txt\"" + "\r\n" + + CONTENT_LENGTH + ": " + file3.length() + "\r\n" + + CONTENT_TYPE + ": text/plain" + "\r\n" + + CONTENT_TRANSFER_ENCODING + ": binary" + "\r\n" + + "\r\n" + + "File 03" + StringUtil.NEWLINE + + "\r\n" + "--" + multipartMixedBoundary + "--" + "\r\n" + "--" + multipartDataBoundary + "--" + "\r\n"; diff --git a/codec-http/src/test/resources/file-03.txt b/codec-http/src/test/resources/file-03.txt new file mode 100644 index 0000000000..b545f1b452 --- /dev/null +++ b/codec-http/src/test/resources/file-03.txt @@ -0,0 +1 @@ +File 03