Over a million developers have joined DZone.

Using Images Stored in HDFS for Web Pages [Code Snippet]

This article is about accessing images stored in Hadoop HDFS via image tags and using them in Java Spring applications.

· Big Data Zone

Read this eGuide to discover the fundamental differences between iPaaS and dPaaS and how the innovative approach of dPaaS gets to the heart of today’s most pressing integration problems, brought to you in partnership with Liaison.

With NiFi 1.00 I ingested a lot of image data from drones, mostly to get metadata like geo. I also ingested a resized version of the image in case I wanted to use it. I found a use for it.

I am pulling this out very simply with Spring for a simple HTML page. So I wrote a quick Java program to pull out fields I stored in Phoenix (from the metadata) and I wanted to display the image. I could have streamed it out of HDFS using HDFS libraries to read the file and then stream it.

sql = "select datekey, fileName, gPSAltitude, gPSLatitude, gPSLongitude, orientation,geolat,geolong,inception from dronedata1 order by datekey asc";
PreparedStatement ps = connection.prepareStatement(sql);
ResultSet res = ps.executeQuery();
while (res.next()) {
    try {
      out.append("<br><br>\n<table width=100%><tr><td valign=top><img src=\"");
      out.append("<td valign=top>Date: ").append(res.getString("datekey"));
      out.append("\n<br>Lat: ").append(res.getString("geolat"));
      out.append("\n<br>Long: ").append(res.getString("geolong"));
    } catch (Exception e) {

It was a lot easier to use the built-in WebHDFS to display an image. Wrapping the Web API call to the image file in an HTML IMG SRC tag loads our image.


It's pretty simple and you can use this with a MEAN application, Python Flask or your non-JVM front-end of choice. And now you have a solid distributed host for your images. I recommend this only for internal sites and public images. Having this data publicly available on the cloud is dangerous!



Discover the unprecedented possibilities and challenges, created by today’s fast paced data climate and why your current integration solution is not enough, brought to you in partnership with Liaison

java,mean,solid,webhdfs,front-end,python,flask,big data

Published at DZone with permission of Tim Spann, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}