title: Possible to send an image to my Servlet as a ByteBuffer?
body: <p>I am attempting to have my android phone connect to my servlet and send it a certain image. The way I figured I would do this, is to use the <code>copyPixelsToBuffer()</code> function and then attempt to send this to the servlet through some output stream(similar to how I would do it in a normal stand alone java application). Will this way work? If so, what kind of stream do I use exactly? Should I just use DataOutputStream and just do something like the following:</p>
  
  <pre><code>ByteBuffer imgbuff;
  Bitmap bm = BitmapFactory.decodeResource(getResources(), R.drawable.icon);
  bm.copyPixelsToBuffer(bm);
  
  ...code...
  URLConnection sc = server.openConnection();
  sc.setDoOutput(true);
  
  DataOutputStream out = new DataOutputStream( sc.getOutputStream() );
  out.write(imgbuff.array());
  out.flush();
  out.close();
  </code></pre>
  
  <p>Note: I understand that this may not be the proper way of connecting to a server using the Android OS but at the moment I'm working on just how to send the image, not the connection (unless this is relevant on how the image is sent).</p>
  
  <p>If this is not a way you'd recommend sending the image to the servlet (I figured a byte buffer would be best but I could be wrong), how would you recommend this to be done?</p>