title: Multipart File Downloading in Spring?
body: <p>I'm developing an application to do some mp3 streaming from my server. I want the  user not to download the whole mp3 file, so the bytes are partially written in the OutputStream of the response.</p>
  
  <p>I know this is also related to HTTP headers and ranges, so I found <a href="https://github.com/davinkevin/Podcast-Server/blob/d927d9b8cb9ea1268af74316cd20b7192ca92da7/src/main/java/lan/dk/podcastserver/utils/multipart/MultipartFileSender.java" rel="nofollow">this class</a> that should work. </p>
  
  <p>However, I'm using Spring MVC Controller and it seems to be not working as expected: the file is fully downloaded and there are two petitions to the Controller in one user request, with the following exception:</p>
  
  <pre><code> java.net.SocketException: Connection reset by peer: socket write error
  </code></pre>
  
  <p>I know the existence of CommonsMultipartResolver, but all I found about this is for uploading files, not downloading. My question is, <strong>is there something in Spring to do this easily?</strong></p>
  
  <p>PD: I attach the code where I'm using the class mentioned above</p>
  
  <pre><code> @RequestMapping(value = "merge/{name:.+\\.mp3}")
      public void playMerged( @PathVariable("name") String audioName, HttpServletRequest request,
              HttpServletResponse response) {
              String mergedAudioPath = service.getMergedAudio(audioName);
       MultipartFileSender.fromPath(Paths.get(mergedAudioPath)).with(request).with(response).serveResource();
     }
  </code></pre>
  
  <p>Thanks!</p>