1

Android large video uploading to php server ,I read many answer in stackoverflow.

uploading video upto 50MB to the server

Android: OutOfMemoryError while uploading video - how best to chunk?

How to send HTTP POST request and receive response?

i tried it but can't works for me even using setChunkedStreamingMode()..When i upload video its give me OutOfMemoryError

when i record video 5 second its works nice but more than 8 or 10 second video app force close due to OutOfMemoryError

MY 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<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(
                            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(">>>>>>>>>>" + response.toString());

                } catch (ClientProtocolException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                }

And i need upload video in Base64 Encoded String.And I know that memory error due to more memory than Heap-size.but i failed to upload video.

LOGCAT

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.<init>(CharArrayBuffer.java:43)
05-31 23:16:12.114: E/AndroidRuntime(17255):    at java.nio.ReadWriteCharArrayBuffer.<init>(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.<init>(String.java:181)
05-31 23:16:12.114: E/AndroidRuntime(17255):    at java.lang.String.<init>(String.java:141)
Community
  • 1
  • 1
Patel Mayur
  • 157
  • 1
  • 3
  • 10
  • i have same task to do in my app, have you succeeded to upload large files ? If yes please guide – Harsh Jul 10 '13 at 17:56

2 Answers2

2

You shouldn't be setting a large byte[] to the entity. It's bound to run out of memory. You could use a FileEntity here.

http://developer.android.com/reference/org/apache/http/entity/FileEntity.html

Some related questions and links

Android send photo using HttpPost/HttpGet

Try this: Sending images using Http Post

Community
  • 1
  • 1
Kumar Bibek
  • 9,016
  • 2
  • 39
  • 68
-5

If the OutOfMemory error is coming from the server, the quick fix would be to update your php.ini variables:

upload_max_filesize = 100M

(or whatever you feel comfortable with)

or if you are POSTing, then you'll also want to change

post_max_size = 100M
Ruebs
  • 1
  • 1