Skip to content

can not upload empty file by POST #3935

@fishjam

Description

@fishjam

Notice

this issue copy from

Expected Behavior

can upload empty file by POST

Actual Behavior

I try to upload lots of files to a file server with POST method, and there are some files are empty(size is 0).
WebClient in WebFlux can not upload them, throw exception: io.netty.handler.codec.EncoderException: java.lang.IllegalStateException: unexpected message type: DefaultFileRegion, state: 0

Steps to Reproduce

 @Test
  public void uploadEmptyFileWithOriginalWebClient() throws IOException {
    File emptyFile = new File("prov2_empty.txt");
    if (!emptyFile.exists()) {
      emptyFile.createNewFile();
    }

    try {
      WebClient orgWebClient = WebClient.builder().build();
      Mono<String> monoUploadEmpty = orgWebClient.post()
          .uri("http://any_web_that_support_post_file")
          .body(BodyInserters.fromResource(new FileSystemResource(emptyFile)))
          .retrieve()
          .bodyToMono(String.class);

      StepVerifier.create(monoUploadEmpty)
          .expectNextCount(1)
          .verifyComplete();

    }finally {
      emptyFile.delete();
    }
}

Possible Solution

Your Environment

case 1:

  • jdk-8.0.232 ,
  • spring-boot-starter-webflux-2.7.18
  • reactor-netty-http-1.0.39

case 2(latest)

  • jdk-21.0.3.9
  • spring-boot-starter-webflux-3.5.6
  • reactor-netty-http-1.2.10

Other

  • I try to reproduce it with reactor-netty code, but can not found yet)

Metadata

Metadata

Assignees

Labels

Type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions