views:

53

answers:

2

I have a java web service through which I upload images to a file server. I want to access these images from my java web app. How can I make the image files (and eventually other static files) available from this file server?

The only thing I could think of was to use Apache Http server as a proxy to my web app for these images, but that circumvents the security measures of the web app.


UPDATE:

  1. Servlet container: Tomcat
  2. Web app is on separate server from images.
  3. Web service is on same server as images and has direct access to file system.
  4. Both web app and service use spring security for authentication/authorization, I want to continue to use this security framework to for image access.
+1  A: 

How are the files stored?

If security is a concern the best option might be to create a Servlet (or something similar) which will load up the image and serve it to the user, once it has checked their credentials.

How you load the image depends on exactly how they're stored, if you can access them via HTTP you can always open up a URLConnection to the file from the Servlet and serve it directly that way (i.e. using the Servlet as a sort of proxy server).

Without more details it's difficult to be specific.

Phill Sacre
Shouldn't this answer be a comment to the question?
Jacob Tomaw
A: 

Sounds similar to Apache Hadoop. Once image/file is requested, you have to make API call and pull the file out and do one of the following:

  1. Store the temp file to the "temp" directory on web accessible server. You will need, some kind of cleaner/gc running in the background to clean those temp files. This is how Facebook does it with photos.

  2. Instead of storing file on the server check the file type and set HTTP Content-type header to the appropriate file type. Image source will look like this <img src="getPicture.jsp?id=1234" />

Alex
Eek, using JSP to serve a binary stream?
BalusC
I might be wrong... worked with Java a while ago. By default JSP return character data, but if explicitly set the content type it will return whatever you want. Either specify in `HttpResponse` or set page derective `<%@ page contentType="image/jpeg"%>`
Alex