title: How to display an image in HTML from Restful java
body: <p>This method used to download an image by the imageID from MongoDB but I need to display an image in the HTML when the user request the URL. 
  <a href="http://localhost:8080/UploadRest/webresources/files/download/file/64165" rel="nofollow">http://localhost:8080/UploadRest/webresources/files/download/file/64165</a></p>
  
  <pre><code>&lt;img src="http://localhost:8080/UploadRest/webresources/files/download/file/64165"&gt;
  </code></pre>
  
  <p><strong>I need to make method display not download</strong></p>
  
  <pre><code>@GET
  @Path("/download/file/{id}")
  @Produces(MediaType.APPLICATION_OCTET_STREAM)
  public Response downloadFilebyID(@PathParam("id")  String id) throws IOException {
  
      Response response = null;
      MongoClientURI uri = new MongoClientURI(CONNECTION_URL);
      MongoClient mongoClient = new MongoClient(uri);
  
      DB mongoDB = mongoClient.getDB(DATABASE_NAME);
  
      //Let's store the standard data in regular collection
      DBCollection collection = mongoDB.getCollection(USER_COLLECION);
  
      logger.info("Inside downloadFilebyID...");
      logger.info("ID: " + id);
  
      BasicDBObject query = new BasicDBObject();
      query.put("_id", id);
      DBObject doc = collection.findOne(query);
      DBCursor cursor = collection.find(query);
  
      if (cursor.hasNext()) {
          Set&lt;String&gt; allKeys = doc.keySet();
          HashMap&lt;String, String&gt; fields = new HashMap&lt;String,String&gt;();
          for (String key: allKeys) {
              fields.put(key, doc.get(key).toString());
          }
  
          logger.info("description: " + fields.get("description"));
          logger.info("department: " + fields.get("department"));
          logger.info("file_year: " + fields.get("file_year"));
          logger.info("filename: " + fields.get("filename"));
  
          GridFS fileStore = new GridFS(mongoDB, "filestore");
          GridFSDBFile gridFile = fileStore.findOne(query);
  
          InputStream in = gridFile.getInputStream();
  
          ByteArrayOutputStream out = new ByteArrayOutputStream();
          int data = in.read();
          while (data &gt;= 0) {
              out.write((char) data);
              data = in.read();
          }
          out.flush();
  
          ResponseBuilder builder = Response.ok(out.toByteArray());
          builder.header("Content-Disposition", "attachment; filename=" + fields.get("filename"));
          response = builder.build();
      } else {
          response = Response.status(404).
          entity(" Unable to get file with ID: " + id).
          type("text/plain").
          build();
      }
      return response;
  }
  </code></pre>