开发者

How to retrieve images stored in file server?

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 ser开发者_StackOverflow社区ver 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.


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.


I'm not sure if this will solve your problem, but it sounds like you should set up a context path that will map a URL to the path on your server. This can be done with tomcat's context files.

For a good explanation of the solution, check out a post on How to Program with Java


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" />

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜