Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-65110

Partial Content pluginfile.php

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Open
    • Priority: Minor
    • Resolution: Unresolved
    • Affects Version/s: 3.4.7
    • Fix Version/s: None
    • Component/s: Files API
    • Labels:
      None
    • Affected Branches:
      MOODLE_34_STABLE

      Description

      Hi,

      We have a user that put a large video file (4gb). When students were seeing this video, we had a problem that, using chorme, pluginfile.php didn't always sent chunks of this video. Chrome sent this header, exemple : 
      Range:
      bytes=1441792-
       
      And from moodle we had this header :
      Content-Length: 4819313765
       
      Content-Range: bytes 1441792-4819313765/4819313765 
       
      After investigating,  we arrive at lib/filelib.php at function byteserving_send_file (line 2558):
       

      $chunksize = 5*(1024*1024); // 1MB chunks - must be less than 2MB!
      if ($handle === false) {
          die;
      }
       
      if (count($ranges) == 1) { //only one range requested
          $length = $ranges[0][2] - $ranges[0][1] + 1;
          header('HTTP/1.1 206 Partial content');
          header('Content-Length: '.$length);
          header('Content-Range: bytes '.$ranges[0][1].'-'.$ranges[0][2].'/'.$filesize);
          header('Content-Type: '.$mimetype);
      

      That if don't check if length of file is greater than chunksize. On our case, we had a lot of  request of full size of file instead of chunks.
       
      On my test I forced that we always sent chuks instead of full size :

      if (count($ranges) == 1) { //only one range requested
          $length = $ranges[0][2] - $ranges[0][1] + 1;
          if($length > $chunksize){
              $length = $chunksize;
              $ranges[0][2]  = $ranges[0][1] + $chunksize;
          }
          header('HTTP/1.1 206 Partial content');
          header('Content-Length: '.$length, true);
          header('Content-Range: bytes '.$ranges[0][1].'-'.$ranges[0][2].'/'.$filesize, true);
          header('Content-Type: '.$mimetype, true);
      

       
       
      Hope that this can be sorted.
       
      Thanks in advance
       
       
       

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              ocimjr Octavio Jr
              Participants:
              Component watchers:
              Matteo Scaramuccia, Jake Dallimore, Jun Pataleta, Ryan Wyllie
            • Votes:
              1 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated: