title: Android: Bitmap uploaded via HttpURLConnection not usable
body: <p>I am using an Android app to upload an image taken with the camera. The camera returns the bitmap, which is passed to the upload task. The server receives the image and saves it, but it appears to be formatted incorrectly; I can not view the image. Is there something I am missing about the Android <code>Bitmap.compress()</code> function? I'm not familiar with image formatting so any help wuld really be appreciated.</p>
  
  <p>Here is the code where the bitmap is written:</p>
  
  <pre><code>HttpURLConnection conn = (HttpURLConnection) url.openConnection();
  conn.setReadTimeout(10000);
  conn.setConnectTimeout(15000);
  conn.setRequestMethod("POST");
  
  
  conn.setDoInput(true);
  conn.setDoOutput(true);
  conn.setRequestProperty("Connection", "Keep-Alive");
  conn.setRequestProperty("ENCTYPE", "multipart/form-data");
  conn.setRequestProperty("Content-Type", "multipart/form-data;boundary=" + boundary);
  conn.setRequestProperty("imageToUpload", "ups.jpg");
  String sUserID = Integer.toString(mUserID);
  OutputStream os = conn.getOutputStream();
  
  os.write((dbHyphen + boundary + lnEnd).getBytes());
  os.write(("Content-Disposition: form-data; name=\"p\"" + lnEnd).getBytes());
  os.write(("Content-Type: text/plain; charset=UTF-8"+ lnEnd).getBytes());
  os.write(lnEnd.getBytes());
  os.write(sUserID.getBytes());os.write(lnEnd.getBytes());
  os.write(lnEnd.getBytes());
  os.write((dbHyphen + boundary + lnEnd).getBytes());
  os.write(("Content-Disposition: form-data; name=\"imageToUpload\";filename="
          + "ups.jpg" + lnEnd).getBytes());
  os.write((lnEnd).getBytes());
  
  ByteArrayOutputStream bos = new ByteArrayOutputStream();
  mImage.compress(Bitmap.CompressFormat.JPEG, 85, bos);
  byte[] bitmapdata = bos.toByteArray();
  
  os.write(bitmapdata);
  os.write((lnEnd).getBytes());
  os.write((dbHyphen + boundary + dbHyphen + lnEnd).getBytes());
  os.close();
  </code></pre>
  
  <p>EDIT: The upload it received and save via php</p>
  
  <pre><code>move_uploaded_file($_FILES['imageToUpload']['tmp_name'], $file_path))
  </code></pre>