-
Notifications
You must be signed in to change notification settings - Fork 38.9k
Closed as not planned
Closed as not planned
Copy link
Labels
status: invalidAn issue that we don't feel is validAn issue that we don't feel is valid
Description
When using Spring WebFlux 7.0.1 (Spring Boot 4.0.2) + JDK 25 to download a PDF (or presumably any binary file) from a REST endpoint, the resulting file is larger than the original and cannot be opened. The same logic works correctly in Spring Boot 2.7.18 + JDK 11 as the file is correctly downloaded and can be opened and viewed.
Steps to reproduce:
- Create a REST endpoint returning raw PDF bytes:
public class TestController {
@GetMapping("/test")
public ResponseEntity<byte[]> test() throws IOException {
ClassPathResource file = new ClassPathResource("sample.pdf");
byte[] data;
try (InputStream in = file.getInputStream()) {
data = in.readAllBytes();
}
return ResponseEntity.ok()
.header(HttpHeaders.CONTENT_TYPE, "application/octet-stream")
.header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"sample.pdf\"")
.header(HttpHeaders.CONTENT_LENGTH, String.valueOf(data.length))
.body(data);
}
}
- Use WebClient 7.0.1 to retrieve the file:
Path outputPath = Path.of("sample.pdf");
webClient.get()
.uri("http://localhost:8080/test")
.retrieve()
.bodyToMono(byte[].class)
.flatMap(bytes -> {
try {
Files.write(outputPath, bytes);
return Mono.empty();
} catch (IOException e) {
return Mono.error(e);
}
})
.block();
- Compare the saved file with the original. The saved file is larger and cannot be opened.
Expected Behavior:
The downloaded file should match the original byte-for-byte.
Downloading the same file using RestTemplate works fine, on both Spring Boot 2 and 4.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
status: invalidAn issue that we don't feel is validAn issue that we don't feel is valid