title: Kafka produce to send image
body: <p>I have the following Kafka producer code. I want to know if I can send image file instead of JSON file? Is there any code reference sending an image file through Kafka producer?</p>
  
  <pre><code>    try {           
                  URL url = getClass().getResource("test.json");
                  File file = new File(url.getPath());
                  Properties props = new Properties();            
                  props.put("bootstrap.servers", "yupsectory.selet.com:9092");
                  props.put("client.id", CLIENT_ID);
                  props.put("key.serializer", "org.apache.kafka.common.serialization.StringSerializer");
                  props.put("value.serializer", "org.apache.kafka.common.serialization.StringSerializer");
                  String jsonData = readFile(file.getAbsolutePath());
                  JSONObject jobj = new JSONObject(jsonData);    
                  System.out.println("jarr: " + jobj.getJSONObject("data").toString());    
  
                  Producer&lt;String, String&gt; producer = new KafkaProducer &lt;&gt;(props);      
                  //Use this util to pull the context that needs to be propagated from the HttpServletRequest
                  Map&lt;String, String&gt; headermap = YupsectoryContextUtil.buildContextMap(request);
                  //Sending a message
                  ProducerRecord&lt;String, String&gt; record = new ProducerRecord&lt;String, String&gt;(topic, jobj.getJSONObject("data").toString());
                  producer.send(record, headermap);           
                  producer.close();                 
              } catch (JSONException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
              }
  </code></pre>