title: Android Large Video Uploading to server?
body: <p>Android large video uploading to php server ,I read many answer in stackoverflow.</p>
  
  <p><a href="https://stackoverflow.com/questions/10276647/uploading-video-upto-50mb-to-the-server">uploading video upto 50MB to the server</a></p>
  
  <p><a href="https://stackoverflow.com/questions/2599305/android-outofmemoryerror-while-uploading-video-how-best-to-chunk">Android: OutOfMemoryError while uploading video - how best to chunk?</a></p>
  
  <p><a href="https://stackoverflow.com/questions/3038409/how-to-send-http-post-request-and-recieve-response/3038747#3038747">How to send HTTP POST request and receive response?</a></p>
  
  <p>i tried it but can't works for me even using <code>setChunkedStreamingMode()</code>..When i upload video its give me <code>OutOfMemoryError</code></p>
  
  <p>when i record video 5 second its works nice but more than 8 or 10 second video app force close due to <code>OutOfMemoryError</code></p>
  
  <p><strong>MY CODE::</strong></p>
  
  <pre><code>                HttpClient httpclient = new DefaultHttpClient();
                  HttpPost httppost = new HttpPost(getString(R.string.login_url)
                          + "uploadvideo");
                  HttpResponse response = null;
                  InputStream inputStream = getContentResolver().openInputStream(
                          Uri.fromFile(myFile));
                  byte[] data = IOUtils.toByteArray(inputStream);
                  String type = getFileExtension(myFile.getName().toString());
  
                  String encodeurl = Base64.encodeBytes(data);
  
                  try {
  
                      List&lt;NameValuePair&gt; nameValuePairs = new ArrayList&lt;NameValuePair&gt;(
                              6);
                      nameValuePairs.add(new BasicNameValuePair("returnformat",
                              "json"));
                      nameValuePairs.add(new BasicNameValuePair("userid",
                              strUserid));
  
                      nameValuePairs.add(new BasicNameValuePair("video",
                              data.toString()));
  
                      nameValuePairs.add(new BasicNameValuePair("type", type));
                      nameValuePairs.add(new BasicNameValuePair("title",
                              strVideoName));
                      nameValuePairs.add(new BasicNameValuePair("description",
                              strVideoComments));
                      httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
  
                      // Execute HTTP Post Request
                      response = httpclient.execute(httppost);
  
                      System.out.println("&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;" + response.toString());
  
                  } catch (ClientProtocolException e) {
                      e.printStackTrace();
                  } catch (IOException e) {
                      e.printStackTrace();
                  }
  </code></pre>
  
  <p>And i need upload video in <code>Base64 Encoded String</code>.And I know that memory error due to more memory than Heap-size.but i failed to upload video.</p>
  
  <p><strong>LOGCAT</strong></p>
  
  <pre><code>05-31 23:16:12.114: E/AndroidRuntime(17255): java.lang.RuntimeException: An error occured while executing doInBackground()
  05-31 23:16:12.114: E/AndroidRuntime(17255):    at android.os.AsyncTask$3.done(AsyncTask.java:200)
  05-31 23:16:12.114: E/AndroidRuntime(17255):    at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:274)
  05-31 23:16:12.114: E/AndroidRuntime(17255):    at java.util.concurrent.FutureTask.setException(FutureTask.java:125)
  05-31 23:16:12.114: E/AndroidRuntime(17255):    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:308)
  05-31 23:16:12.114: E/AndroidRuntime(17255):    at java.util.concurrent.FutureTask.run(FutureTask.java:138)
  05-31 23:16:12.114: E/AndroidRuntime(17255):    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088)
  05-31 23:16:12.114: E/AndroidRuntime(17255):    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)
  05-31 23:16:12.114: E/AndroidRuntime(17255):    at java.lang.Thread.run(Thread.java:1027)
  05-31 23:16:12.114: E/AndroidRuntime(17255): Caused by: java.lang.OutOfMemoryError: (Heap Size=20103KB, Allocated=15700KB, Bitmap Size=0KB)
  05-31 23:16:12.114: E/AndroidRuntime(17255):    at java.nio.CharArrayBuffer.&lt;init&gt;(CharArrayBuffer.java:43)
  05-31 23:16:12.114: E/AndroidRuntime(17255):    at java.nio.ReadWriteCharArrayBuffer.&lt;init&gt;(ReadWriteCharArrayBuffer.java:47)
  05-31 23:16:12.114: E/AndroidRuntime(17255):    at java.nio.BufferFactory.newCharBuffer(BufferFactory.java:82)
  05-31 23:16:12.114: E/AndroidRuntime(17255):    at java.nio.CharBuffer.allocate(CharBuffer.java:53)
  05-31 23:16:12.114: E/AndroidRuntime(17255):    at java.nio.charset.CharsetDecoder.allocateMore(CharsetDecoder.java:261)
  05-31 23:16:12.114: E/AndroidRuntime(17255):    at java.nio.charset.CharsetDecoder.decode(CharsetDecoder.java:218)
  05-31 23:16:12.114: E/AndroidRuntime(17255):    at java.nio.charset.Charset.decode(Charset.java:488)
  05-31 23:16:12.114: E/AndroidRuntime(17255):    at java.lang.String.&lt;init&gt;(String.java:181)
  05-31 23:16:12.114: E/AndroidRuntime(17255):    at java.lang.String.&lt;init&gt;(String.java:141)
  </code></pre>