title: Spring Webflux: FilePart transferTo adds invisible character at the first line
body: <p>I'm using Spring Boot + webflux application and trying to implement Rest API endpoint for files uploading. Everything works fine but <code>org.springframework.http.codec.multipart.FilePart#transferTo</code> method adds some invisible character at first line first position.<br>
  In the screenshot below you can find that <code>original.toml</code> file has first line in blue and <code>uploaded.toml</code> has gray (Atom Editor doesn't recognize <code>[config]</code> as a valid toml key entry).   </p>
  
  <p><a href="https://i.stack.imgur.com/tqn29.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/tqn29.png" alt="screen"></a></p>
  
  <p>Also <code>diff</code> gives me:</p>
  
  <pre><code>1c1
  &lt; [config]
  ---
  &gt; [config]
  </code></pre>
  
  <p>My code is:</p>
  
  <pre><code>import java.io.File;
  import java.io.IOException;
  import java.nio.file.Files;
  import java.nio.file.Path;
  import java.nio.file.Paths;
  import lombok.extern.slf4j.Slf4j;
  import org.springframework.http.MediaType;
  import org.springframework.http.codec.multipart.FilePart;
  import org.springframework.http.codec.multipart.Part;
  import org.springframework.web.bind.annotation.PostMapping;
  import org.springframework.web.bind.annotation.RequestBody;
  import org.springframework.web.bind.annotation.RestController;
  import reactor.core.publisher.Flux;
  import reactor.core.publisher.Mono;
  
  @RestController
  @Slf4j
  public class UploadController {
  
    @PostMapping(value = "/upload",
        consumes = MediaType.MULTIPART_FORM_DATA_VALUE,
        produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public Flux&lt;String&gt; uploadFiles(@RequestBody Flux&lt;Part&gt; parts) {
      return
          parts
              .filter(p -&gt; p instanceof FilePart)
              .cast(FilePart.class)
              .flatMap(this::saveFile)
              .map(File::getName)
              .doFinally(s -&gt; log.debug("Upload files process completed with signal: {}", s));
    }
  
    private Mono&lt;File&gt; saveFile(FilePart filePart) {
      Path target = Paths.get("").resolve(filePart.filename());
      try {
        Files.deleteIfExists(target);
        File file = Files.createFile(target).toFile();
  
        return filePart.transferTo(file)
            .map(r -&gt; file);
      } catch (IOException e) {
        throw new RuntimeException(e);
      }
    }
  
  }
  </code></pre>
  
  <p>The issue is in <code>filePart.transferTo(file)</code> method. If I comment this line and just write custom string to the file then all is well, no any new symbols appear.</p>
  
  <p>May be does it happen because of encoding? But i didn't find how can I specify charset for file transfer.</p>
  
  <p>Please help me to solve this problem.</p>