title: Upload image from J2ME client to a Servlet
body: <p>I want to send an image from a J2ME client to a Servlet.</p>
  
  <p>I am able to get a byte array of the image and send it using HTTP POST.</p>
  
  <pre><code>conn = (HttpConnection) Connector.open(url, Connector.READ_WRITE, true);
  conn.setRequestMethod(HttpConnection.POST);
  conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
  os.write(bytes, 0, bytes.length); // bytes = byte array of image
  </code></pre>
  
  <p>This is the Servlet code:</p>
  
  <pre><code>String line;
  BufferedReader r1 = new BufferedReader(new InputStreamReader(in));
  while ((line = r1.readLine()) != null) {
      System.out.println("line=" + line);
      buf.append(line);
  }
  String s = buf.toString();
  byte[] img_byte = s.getBytes();
  </code></pre>
  
  <p>But the problem I found is, when I send bytes from the J2ME client, some bytes are lost. Their values are <code>0A</code> and <code>0D</code> hex. Exactly, the Carriage Return and Line Feed.</p>
  
  <p>Thus, either POST method or <code>readLine()</code> are not able to accept <code>0A</code> and <code>0D</code> values.</p>
  
  <p>Any one have any idea how to do this, or how to use any another method?</p>