IAmYourFaja
IAmYourFaja

Reputation: 56914

How to stream custom video from Tomcat

I have a Java backend running on Tomcat 7. I'd like to add support for an HTTP request that would begin streaming an MP4 video from Java code in Tomcat, and not sure where to begin. I believe HTTP GET somehow supports A/V streaming, but not entirely sure.

Let's pretend that the MP4 file is located at /opt/videos/myvid.mp4, and that the Tomcat instance has file permissions to read/write to that directory and file. Now let's pretend that an HTTP GET (or whatever supports streaming) request comes in, and we need to start streaming myvid.mp4 to the client - in pure Java, from inside a Controller class. How would this work?

Upvotes: 3

Views: 5354

Answers (1)

Toni Bünter
Toni Bünter

Reputation: 103

I had to accomplish a similar task a year ago. I found a nice short and working servlet on: http://balusc.omnifaces.org/2009/02/fileservlet-supporting-resume-and.html

Actually, tomcat itself is doing streaming quite well. But, I did not figure out how to use files outside the webapp/war directory.

Upvotes: 1

Related Questions