@Test
public void customContentDisposition() throws IOException {
Resource logo = new ClassPathResource("/org/springframework/http/converter/logo.jpg");
Flux<DataBuffer> buffers = DataBufferUtils.read(logo, new DefaultDataBufferFactory(), 1024);
long contentLength = logo.contentLength();
MultipartBodyBuilder bodyBuilder = new MultipartBodyBuilder();
bodyBuilder.part("resource", logo)
.headers(h -> h.setContentDispositionFormData("resource", "spring.jpg"));
bodyBuilder.asyncPart("buffers", buffers, DataBuffer.class)
.headers(h -> {
h.setContentDispositionFormData("buffers", "buffers.jpg");
h.setContentType(MediaType.IMAGE_JPEG);
h.setContentLength(contentLength);
});
MultiValueMap<String, HttpEntity<?>> multipartData = bodyBuilder.build();
Map<String, Object> hints = Collections.emptyMap();
this.writer.write(Mono.just(multipartData), null, MediaType.MULTIPART_FORM_DATA,
this.response, hints).block();
MultiValueMap<String, Part> requestParts = parse(hints);
assertEquals(2, requestParts.size());
Part part = requestParts.getFirst("resource");
assertTrue(part instanceof FilePart);
assertEquals("spring.jpg", ((FilePart) part).filename());
assertEquals(logo.getFile().length(), part.headers().getContentLength());
part = requestParts.getFirst("buffers");
assertTrue(part instanceof FilePart);
assertEquals("buffers.jpg", ((FilePart) part).filename());
assertEquals(logo.getFile().length(), part.headers().getContentLength());
}