title: Upload File via DataOutputStream does not work
body: <p>Im writing an Android App. This App should upload some pictures to my server via POST.
  It is working if I use picture smaller then 1MB.
  But if i use larger images the log says me that the image was uploaded but the image is not on the server.
  The post_max_size is 4MB</p>
  
  <p>My Method is from a stackoverflow solution and should work but it doesnt and I dont know why.</p>
  
  <pre><code>// http post
          ArrayList&lt;NameValuePair&gt; nameValuePairs = new ArrayList&lt;NameValuePair&gt;();
          nameValuePairs.add(new BasicNameValuePair("c_user_id", params[1]));
          nameValuePairs.add(new BasicNameValuePair("c_task_id", params[2]));
          nameValuePairs.add(new BasicNameValuePair("c_comment", params[3]));
          try {
              HttpClient httpclient = new DefaultHttpClient();
              HttpPost httppost = new HttpPost(phpPath + "insert_task.php");
              httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
              HttpResponse response = httpclient.execute(httppost);
              HttpEntity entity = response.getEntity();
  
          } catch (Exception e) {
              Log.e("log_tag", "Error in http connection" + e.toString());
              this.cancel(true);
  
          }
  
          String Tag = "UPLOADER";
          String urlString = phpPath + "upload_task.php?user_id=" + params[1]
                  + "&amp;task_id=" + params[2];
          HttpURLConnection conn = null;
  
          String exsistingFileName = params[0];
          String lineEnd = "\r\n";
          String twoHyphens = "--";
          String boundary = "*****";
          try {
              // ------------------ CLIENT REQUEST
  
              Log.e(Tag, "Inside second Method");
  
              FileInputStream fileInputStream = new FileInputStream(new File(
                      exsistingFileName));
  
              // open a URL connection to the Servlet
  
              URL url = new URL(urlString);
  
              // Open a HTTP connection to the URL
  
              conn = (HttpURLConnection) url.openConnection();
  
              // Allow Inputs
              conn.setDoInput(true);
  
              // Allow Outputs
              conn.setDoOutput(true);
  
              // Don't use a cached copy.
              conn.setUseCaches(false);
  
              // Use a post method.
              conn.setRequestMethod("POST");
  
              conn.setRequestProperty("Connection", "Keep-Alive");
  
              conn.setRequestProperty("Content-Type",
                      "multipart/form-data;boundary=" + boundary);
  
              DataOutputStream dos = new DataOutputStream(
                      conn.getOutputStream());
  
              dos.writeBytes(twoHyphens + boundary + lineEnd);
              dos.writeBytes("Content-Disposition: post-data; name=uploadedfile;filename="
                      + exsistingFileName + "" + lineEnd);
              dos.writeBytes(lineEnd);
  
              Log.e(Tag, "Headers are written");
  
              // create a buffer of maximum size
              int bytesAvailable = fileInputStream.available();   
              int maxBufferSize = 1 * 1024;
              int bufferSize = Math.min(bytesAvailable, maxBufferSize);
              byte[] buffer = new byte[bufferSize];
              buffer = new byte[bufferSize];
              int bytesRead = fileInputStream.read(buffer, 0, bufferSize);
              // Read file
  
              Log.e("Image length", bytesAvailable + "");
              try {
                  while (bytesRead &gt; 0) {
                      try {
                          dos.write(buffer, 0, bufferSize);
                      } catch (OutOfMemoryError e) {
                          e.printStackTrace();
  
                      }
                      bytesAvailable = fileInputStream.available();
                      bufferSize = Math.min(bytesAvailable, maxBufferSize);
                      bytesRead = fileInputStream.read(buffer, 0, bufferSize);
                  }
              } catch (Exception e) {
  
              }
              dos.writeBytes(lineEnd);
              dos.writeBytes(twoHyphens + boundary + twoHyphens + lineEnd);
  
  
  
              Log.i("File Name in Server : ", exsistingFileName);
  
              fileInputStream.close();
              dos.flush();
              dos.close();
              dos = null;
          } catch (Exception ex) {
              // Exception handling
  
              Log.e("Send file Exception", ex.getMessage() + "");
              ex.printStackTrace();
          }
  </code></pre>