title: spring webflux Flux<DataBuffer> convert to InputStream
body: <p>I'm currently working on Spring WebFlux.
  I'm trying to upload large file (70mo) using Spring WebFlux.</p>
  <p>My Controller</p>
  <pre><code>@RequestMapping(method = RequestMethod.POST, consumes = MediaType.MULTIPART_FORM_DATA_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
  public Flux&lt;String&gt; uploadHandler(@RequestBody Flux&lt;Part&gt; fluxParts, @RequestParam(value = &quot;categoryType&quot;) String categoryType, @PathVariable(value = &quot;traceabilityReportUuid&quot;) String traceabilityUuid) {
      return documentHandler.upload(fluxParts, UUID.fromString(traceabilityUuid), categoryType);
  }
  </code></pre>
  <p>My Service</p>
  <pre><code>public Flux&lt;String&gt; upload(Flux&lt;Part&gt; fluxParts, UUID traceabilityUuid, String categoryType) {
  
      return fluxParts
              .filter(part -&gt; part instanceof FilePart)
              .ofType(FilePart.class)
              .flatMap(p -&gt; this.upload(p, traceabilityUuid, categoryType));
  
  
  }
  
  
  private Mono&lt;String&gt; upload(FilePart filePart, UUID traceabilityUuid, String categoryType) {
  
      return filePart.content().collect(InputStreamCollector::new, (t, dataBuffer) -&gt; t.collectInputStream(dataBuffer.asInputStream()))
              .flatMap(inputStreamCollector -&gt; {
                  upload(traceabilityUuid, inputStreamCollector.getInputStream(), filePart.filename(), categoryType);
  
                  return Mono.just(&quot;OK&quot;);
              });
  }
  </code></pre>
  <p>My Collector</p>
  <pre><code>public class InputStreamCollector {
  
      private InputStream is;
  
      public void collectInputStream(InputStream is) {
          if (this.is == null) this.is = is;
          this.is = new SequenceInputStream(this.is, is);
      }
  
      public InputStream getInputStream() {
          return this.is;
      }
  }
  </code></pre>
  <p>And at the end, I retrieve the full inputstream by this way : <code>inputStreamCollector.getInputStream()</code> and pass to my object.</p>
  <p>And I use this object in order to send to bucket S3.</p>
  <p>But before sending to S3, I must to convert it into file (using apache tools), I have a stackoverflow exception.</p>
  <pre><code>java.lang.StackOverflowError: null
  at java.base/java.io.SequenceInputStream.read(SequenceInputStream.java:156)
  at java.base/java.io.SequenceInputStream.read(SequenceInputStream.java:156)
  at java.base/java.io.SequenceInputStream.read(SequenceInputStream.java:156)
  at java.base/java.io.SequenceInputStream.read(SequenceInputStream.java:156)
  at java.base/java.io.SequenceInputStream.read(SequenceInputStream.java:156)
  at java.base/java.io.SequenceInputStream.read(SequenceInputStream.java:156)
  at java.base/java.io.SequenceInputStream.read(SequenceInputStream.java:156)
  at java.base/java.io.SequenceInputStream.read(SequenceInputStream.java:156)
  </code></pre>
  <p>it works fine with a small file (7mo ..)</p>
  <p>Do you have an idea to resolve my issue please ?</p>