title: How can I convert FilePart to byte[] in Spring 5 MVC
body: <p>I have controller method that receives and uploaded file from a web form. How can I extract the byte array out of the FilePart and save it to DB? </p>
  
  <p>I can do it by saving the FilePart to a file using FilePart.transferTo() but that seems slow and ugly. Any nicer way of doing it? </p>
  
  <pre><code>import org.springframework.http.codec.multipart.FilePart;
  import org.springframework.web.bind.annotation.*;
  
  
   Mono&lt;UploadResult&gt; uploadFile(@RequestParam("files") FilePart file){
  
      byte[] fileAsByteArray = convertFilePartToByteArray(file);
  
      fileService.saveByteArrayToDB(fileAsByteArray);
  
      /* Rest of the method */
   }
  </code></pre>