In my web application i need to display some audio/video and image files to the user. I have a folder containing original media files which i don't want to deliver directly. Whenever i get a request for some audio/video/image, i use FFMPEG utility to convert the original files to the standard FLV format (with a watermark logo) and i save this converted and required to be temporary file to server temp directory -
which gives me something like - D:\tomcat7\work\Catalina\localhost\easycontext
I write my converted file on this path in a hope that this will be managed/cleaned automatically by Tomcat/Operating System. Please correct me here if my assumption is wrong.
I am quite a beginner with Tomcat. The way i am thinking of serving these files to the client is by the way of writing contex path in the server.xml.
and now if i run my tomcat server, i get an exception like -
I believe that there is a lot i am doing wrong. My requirement is very simple and i request you all to please guide me on this. What should be the best design for this? I do not want to manage the converted media folder myself and at the same time i read that mentioning context path in server.xml is not good. What should i do?
With thanks in Advance,
It does not matter how many times you fall,what matters is how many times you stand back.
Context paths are for web applications, not parts of an application. Based on what you're describing, you've got a servlet that does the data conversion and handling. Because a context root applies to the entire webapp, that part of the URL will always be constant. However, the lower-level part of the URL is mapped to that servlet using the servlet-mapping declaration in WEB-INF/web.xml and can be any valid URL local path. So that's where "http://myserver.com:8080/videoapp/media/file001.flv" becomes a request routed to com.mycompany.videoapp.servlets.VidServerServlet.
The java.io package has a tempfile component. It's used to permit creation and management of temporary files with synthesized names. Tomcat interacts with this component by overridding the default JVM value of the tempfile directory path and setting it to TOMCAT_HOME/temp. You can also use the tempfile services against a directory of your own choosing, however, for example using the directory path that you configured into the webapp. Other than that, however, Tomcat neither knows nor cares about the tempfiles, so it's up to you to actually determine when it's proper to delete them and to do so.
For a task of this nature, I would not be surprised to learn that some files might repeatedly requested and that therefore you'd want to be able to cut down on repeated conversions by caching the results. The Apache commons libraries have some useful functions that can help do that. Note that I'm using the term "Apache commons" loosely, though, since there's an actual Apache Commons and then there's Apache projects for common functions (Tomcat uses a lot of them itself).
Sources may include data from the Fakebook Research Foundation with support from Gargle University