title: Upload Large Video to PHP Server from Android Crashes Application
body: <p>I am uploading large video to php server, which crashes application.</p>
  
  <p>So, I have used   <strong>conn.setChunkedStreamingMode(maxBufferSize);</strong>
  <br>But it gives <strong>RESPONCE : Request Entity Too Large</strong></p>
  
  <p>Server side Video is accepted in encoded form, so I used Base64 to encode.</p>
  
  <p>I am using JSON web-service to Upload video</p>
  
  <pre><code>    uploadvideo(&amp;userid,&amp;video,&amp;title,&amp;description,&amp;type)
  </code></pre>
  
  <p>I have searched many but Can't get solution.
  Can any-one tell me</p>
  
  <p><a href="http://www.coderzheaven.com/2012/03/29/uploading-audio-video-or-image-files-from-android-to-server/" rel="nofollow">http://www.coderzheaven.com/2012/03/29/uploading-audio-video-or-image-files-from-android-to-server/</a></p>
  
  <p><a href="http://www.mail-archive.com/android-developers@googlegroups.com/msg92856.html" rel="nofollow">http://www.mail-archive.com/android-developers@googlegroups.com/msg92856.html</a></p>
  
  <p>which one is better AND HOW TO ADD PARAMETERS?</p>
  
  <p>I have used code somethin  like dis</p>
  
  <pre><code>try {
      FileInputStream fileInputStream = new FileInputStream(myFile.getAbsolutePath());        //(new File(selectedPath) );
      // 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.setChunkedStreamingMode(maxBufferSize);
      conn.setRequestProperty("Connection", "Keep-Alive");
      conn.setRequestProperty("Content-Type", "multipart/form-data;boundary="+boundary);
  
      dos = new DataOutputStream( conn.getOutputStream() );
      dos.writeBytes(twoHyphens + boundary + lineEnd);
      dos.writeBytes("Content-Disposition: form-data; name=\"userid\""+ lineEnd + lineEnd);
      dos.writeBytes(strUserid+lineEnd);
  
      bytesAvailable = fileInputStream.available();
      bufferSize = Math.min(bytesAvailable, maxBufferSize);
      buffer = new byte[bufferSize];
  
      // read file and write it into form...
      bytesRead = fileInputStream.read(buffer, 0, bufferSize);
      while (bytesRead &gt; 0)
      {
          dos.write(buffer, 0, bufferSize);
          bytesAvailable = fileInputStream.available();
          bufferSize = Math.min(bytesAvailable, maxBufferSize);
          bytesRead = fileInputStream.read(buffer, 0, bufferSize);
      }
      String encodeurl = Base64.encodeBytes(buffer);
  
      dos.writeBytes(twoHyphens + boundary + lineEnd);
      dos.writeBytes("Content-Disposition: form-data; name=\"video\""+ lineEnd + lineEnd);
      dos.writeBytes(encodeurl+lineEnd);
  
      dos.writeBytes(twoHyphens + boundary + lineEnd);
      dos.writeBytes("Content-Disposition: form-data; name=\"title\""+ lineEnd + lineEnd);
      dos.writeBytes(strVideoName+lineEnd);
  
      dos.writeBytes(twoHyphens + boundary + lineEnd);
      dos.writeBytes("Content-Disposition: form-data; name=\"description\""+ lineEnd + lineEnd);
      dos.writeBytes(strVideoComments+lineEnd);
  
      dos.writeBytes(twoHyphens + boundary + lineEnd);
      dos.writeBytes("Content-Disposition: form-data; name=\"type\""+ lineEnd + lineEnd);
      dos.writeBytes(type+lineEnd);
  
      responseMsg = conn.getResponseMessage();
      // close streams
      System.out.println("Debug  File is written");
      fileInputStream.close();
      dos.flush();
      dos.close();
      }
      catch (MalformedURLException ex)
      {
          System.out.println(("Debug  Error: " + ex.getMessage()));
      }
      catch (IOException ioe)
      {
          System.out.println("Debug  Error: " + ioe.getMessage());
      }
      //------------------ read the SERVER RESPONSE
      try {
          inStream = new DataInputStream ( conn.getInputStream() );
          System.out.println("Input Stream :: "+inStream.toString());
          String str;
  
          while (( str = inStream.readLine()) != null)
          {
              System.out.println("Debug  Server Response "+str);
          }
          inStream.close();
  
      }
      catch (IOException ioex){
           System.out.println("Debug  Error: " + ioex.getMessage());
      }
  </code></pre>