While sending a file I receive an array of bytes. I always have a problem with webflux to receive an array. the error thrown as below :
org.springframework.core.io.buffer.DataBufferLimitException: Exceeded limit on max bytes to buffer : 262144
    at org.springframework.core.io.buffer.LimitedDataBufferList.raiseLimitException(LimitedDataBufferList.java:101)
    Suppressed: reactor.core.publisher.FluxOnAssembly$OnAssemblyException
Do you now how to resolve that in webflux ?
This worked for me:
Create a @Bean in one of your configuration classes or the main SpringBootApplication class:
@Bean
public WebClient webClient() {
    final int size = 16 * 1024 * 1024;
    final ExchangeStrategies strategies = ExchangeStrategies.builder()
        .codecs(codecs -> codecs.defaultCodecs().maxInMemorySize(size))
        .build();
    return WebClient.builder()
        .exchangeStrategies(strategies)
        .build();
}
Next, go to your desired class where you want to use the WebClient:
@Service
public class TestService {
    @Autowired
    private WebClient webClient;
    public void test() {
        String out = webClient
            .get()
            .uri("/my/api/endpoint")
            .retrieve()
            .bodyToMono(String.class)
            .block();
        System.out.println(out);
    }
}
I suppose this issue is about adding a new spring.codec.max-in-memory-size configuration property in Spring Boot. Add it to the application.yml file like:
spring:
  codec:
    max-in-memory-size: 10MB
                        Set the maximum bytes (in megabytes) in your Spring Boot application.properties configuration file like below:
spring.codec.max-in-memory-size=20MB
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With