Sunday, 19 April 2015

Facing problem on Upload Large Size Video on the Server using the Multipart entity in Android

Hello Friends,

         While developing any application's which contains the functionality like uploading large sizes of images as well as the videos ,we are always facing problem of OutOfMemory in android.

Today i am going to share my knowledge with you about an uploading the large video's on server which i recently faced in one of application. The uploading video was working fine if the video size is less than 16MB. But as it increases the OutOfMemory problem started occurring.]
So after doing the research on it i found solution of it which you can use.

Solution 1: 
 HttpURLConnection m_httpconnection = null;  
 m_httpconnection = (HttpURLConnection) new URL(m_wsUrl).openConnection();  m_httpconnection.setConnectTimeout(2000);  
         m_httpconnection.setDoInput(true);  
         m_httpconnection.setDoOutput(true);  
         m_httpconnection.setUseCaches(false);  
 m_httpconnection.setChunkedStreamingMode(1024);   
 m_httpconnection.setRequestMethod("POST");  
 m_httpconnection.setRequestProperty("Connection", "Keep-Alive");  
 m_httpconnection.setRequestProperty("Content-Type", "multipart/form-data;boundary=" + BOUNDARY);  
In the above solution I have used method  setChunkedStreamingMode(1024), which will help you chunk your whole data into specific size so that you do not need to keep your entire file in memory.

You can also use  m_httpConnection.setFixedLengthStreamingMode(1024);  method if the length of HTTP request body is known ahead. It sets fixed length to enable streaming without buffering. Sets after connection will cause an exception.

Thank you.

No comments:

Post a Comment