Video download/stream using Java servlet

前端 未结 1 1605
我寻月下人不归
我寻月下人不归 2021-01-05 12:29

I am trying to download a video file in my server when the client access URL similar to this:

http://localhost:8088/openmrs/moduleServlet/patientnarratives/v         


        
相关标签:
1条回答
  • 2021-01-05 13:03

    The servlet which you found is indeed insuitable for the purpose of streaming a video file. It's more intented as a simple file download servlet for static files like PDF, XLS, etc.

    A lot of video players require that the server supports so-called HTTP range requests. I.e. it must be able to return a specific byte range of the video file by a request with a Range header. For example, only the bytes from index 1000 until 2000 on a file of 10000 bytes long. This is mandatory in order to be able to skip a certain range of the video stream quickly enough without the need to download the whole file and/or to improve buffering speed by creating multiple HTTP connections which each requests a different part of the video file.

    This is however a lot of additional code in the servlet which requires a well understanding of the HTTP Range specification. A ready to use example is provided in flavor of this extended file servlet by the very same author of the file servlet which you found. In your specific case it's perhaps recommendable to save the file to local disk file system based cache first (e.g. by File#createTempFile() and some key in HTTP session), so that you don't need to obtain it from the external service again and again.

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