开发者

Store and display image file in Apache Cassandra

I have read jpg/png file through string buffer using cassandra Hector APIs开发者_StackOverflow中文版. Now i want to show that file on html page.

Is there any way to show that file on html page without creating temporary file on local file system. Because I have set up Cassandra in Cluster mode and do not want to restrict me to one machine to store these temporary files.


Since you have retrieved the image data, you have kind of service for serving the byte array of the image. You can map a servlet to certain URL(for ex. /imagepreview), in the URL you will have the id of the image. The id can be part of the path (in RESTful manner) or as URL parameter - it is your choice.

Next in your HTML file you can add image tag "img" and the "src" attribute will have the URL to the servlet with certain image id. Like this :

<img src="/imagepreview?id=83745"></img>

Here is simplified path of serving the request:

  • The servlet will "know" how to read the image id
  • it will use the image service to retrieve the image bytes
  • it will full-fill the HTTP response with the bytes and will set the necessary headers.
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜