Nodejs - HTTP Range support / Partial file download

后端 未结 1 666
清歌不尽
清歌不尽 2021-02-02 03:15

I am creating a music web app that streams MP3s that I have stored in MongoDB(GridFS).

My Question: How can I add http range support so that I can start streaming the au

1条回答
  •  走了就别回头了
    2021-02-02 03:46

    The client will send a Range header specifying the absolute starting and ending bytes followed by total file length or '*'.

    Examples:

      . The first 500 bytes:
       bytes 0-499/1234
    
      . The second 500 bytes:
       bytes 500-999/1234
    
      . All except for the first 500 bytes:
       bytes 500-1233/1234
    
      . The last 500 bytes:
       bytes 734-1233/1234
    

    The server should then return a response code 206 (Partial content) and the Content-Length should be only the amount of data transmitted.

    In the case the range is wrong, the server should either return 416 (Requested range not satisfiable) with a Content-Range field of bytes */* or should ignore the range request and return a 200 with the entire body of the file.

    The server must also send an Accept-Ranges field with the value of the accepted range unit, in this case bytes. But the range unit can be any custom range unit you want.

    Source: rfc2616

    0 讨论(0)
提交回复
热议问题