title: How do I return a video with Spring MVC so that it can be navigated using the html5 <video> tag?
body: <p>If I have a file in the web server (Tomcat) and create a  tag, I can watch the video, pause it, navigate through it, and restart it after it finishes.</p>
  
  <p>But if I create a REST interface that sends the video file when requested, and add its URL to a  tag, I can only play and pause. <strong>No rewinding, no fast forward, no navigating</strong>, nothing.</p>
  
  <p>So, is there a way for this to be fixed? Am I missing something somewhere?</p>
  
  <p><strong>Video files are in the same server as the REST interface</strong>, and the REST interface only checks session and sends the video after finding out which one it should send.</p>
  
  <p>These are the methods I've tried so far. They all work, but none of them allow navigating.</p>
  
  <h1>Method 1, ResponseEntity:</h1>
  
  <pre><code>/*
   * This will actually load the whole video file in a byte array in memory,
   * so it's not recommended.
   */
  @RequestMapping(value = "/{id}/preview", method = RequestMethod.GET)
  @ResponseBody public ResponseEntity&lt;byte[]&gt; getPreview1(@PathVariable("id") String id, HttpServletResponse response) {
      ResponseEntity&lt;byte[]&gt; result = null;
      try {
          String path = repositoryService.findVideoLocationById(id);
          Path path = Paths.get(pathString);
          byte[] image = Files.readAllBytes(path);
  
          response.setStatus(HttpStatus.OK.value());
          HttpHeaders headers = new HttpHeaders();
          headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
          headers.setContentLength(image.length);
          result = new ResponseEntity&lt;byte[]&gt;(image, headers, HttpStatus.OK);
      } catch (java.nio.file.NoSuchFileException e) {
          response.setStatus(HttpStatus.NOT_FOUND.value());
      } catch (Exception e) {
          response.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value());
      }
      return result;
  }
  </code></pre>
  
  <h1>Method 2, Stream copy:</h1>
  
  <pre><code>/*
   * IOUtils is available in Apache commons io
   */
  @RequestMapping(value = "/{id}/preview2", method = RequestMethod.GET)
  @ResponseBody public void getPreview2(@PathVariable("id") String id, HttpServletResponse response) {
      try {
          String path = repositoryService.findVideoLocationById(id);
          File file = new File(path)
          response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
          response.setHeader("Content-Disposition", "attachment; filename="+file.getName().replace(" ", "_"));
          InputStream iStream = new FileInputStream(file);
          IOUtils.copy(iStream, response.getOutputStream());
          response.flushBuffer();
      } catch (java.nio.file.NoSuchFileException e) {
          response.setStatus(HttpStatus.NOT_FOUND.value());
      } catch (Exception e) {
          response.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value());
      }
  }
  </code></pre>
  
  <h1>Method 3, FileSystemResource:</h1>
  
  <pre><code>@RequestMapping(value = "/{id}/preview3", method = RequestMethod.GET)
  @ResponseBody public FileSystemResource getPreview3(@PathVariable("id") String id, HttpServletResponse response) {
      String path = repositoryService.findVideoLocationById(id);
      return new FileSystemResource(path);
  }
  </code></pre>