-1

How to Upload Large Video FIle on server? I want up to 50 to 60mb video File on Server but I dont know how its possible. I could not Upload up to 15mb video file on server. Please have any solution Then let me know.

public static String postRequestvideo_test(String url, byte[] video, byte[] image, List data) {

    String result = "";
    Log.i("video_upload", video + "");
    try {
        HttpPost httpPost = new HttpPost(url);
        // StringEntity se;
        // se = new StringEntity(data, HTTP.UTF_8);
        // httpPost.setEntity(new UrlEncodedFormEntity(data));
        httpPost.setEntity(new UrlEncodedFormEntity(data, "UTF-8"));
        MultipartEntity mpEntity = new MultipartEntity(
                HttpMultipartMode.BROWSER_COMPATIBLE);

        mpEntity.addPart("video_thumbnail", new ByteArrayBody(image,
                "imagename" + ".jpeg"));
        mpEntity.addPart("video",
                new ByteArrayBody(video, "hyman" + ".mp4"));

        mpEntity.addPart("user_key", new StringBody("user_key_test"));
        mpEntity.addPart("video_name", new StringBody("video_name_test"));
        mpEntity.addPart("video_duration", new StringBody(
                "video_duration_test"));

        mpEntity.addPart("video_thumbnail_extn", new StringBody(
                "video_thumbnail_extn_test"));
        httpPost.setEntity(mpEntity);
        HttpParams httpParameters = new BasicHttpParams();
        int timeoutConnection = 90000000;
        HttpConnectionParams.setConnectionTimeout(httpParameters,
                timeoutConnection);
        int timeoutSocket = 90000000;
        HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket);

        DefaultHttpClient httpClient = new DefaultHttpClient(httpParameters);
        BasicHttpResponse httpResponse = (BasicHttpResponse) httpClient
                .execute(httpPost);
        HttpEntity entity = httpResponse.getEntity();
        if (entity != null) {
            result = EntityUtils.toString(entity);
            result = result.trim();
        }
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    } catch (ParseException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (Exception e) {
        return "-333" + e.toString();
    }
    return result;
}
valkesh patel
  • 116
  • 11

2 Answers2

2

// Old Answer, please CHECK BELOW FOR NEW ANSWER

The problem you're having is probably trying to load the entire video (or for that matter any large file) in the memory at once, since the app has a maximum limited memory allowed, if you exceed that, it will cause the application to crash and give you Out of Memory exception.

What you need to do is open a connection and set it to "Keep-Alive", then open a FileInputStream for reading your video, and start reading and sending as chunks (1-4 MB is probably a good size) until all the file bytes are sent. That way you ensure the stream is sending the data while you're not exceeding your allowed memory limit for your app.

// New Answer

Please note that the above is an old answer, right now I only use MultipartEntity (org.apache.http.entity.mime.MultipartEntityBuilder) and it takes care of any file size on its own.

NightwareSystems
  • 433
  • 5
  • 17
  • Thank you for reply. You r right for that when any large file upload then everybody can facing problems. but now a day, I have found some solution of that and its uses full everybody working with uploading large file. we have done this on divide file of small part like. i have 30mb file and i have chunk the file in small part and upload the file. – valkesh patel Jan 21 '15 at 10:26
2
mpEntity.addPart(Constant.VIDEO, new FileBody(file,
                         "video/mp4"));

I just put it and it's done.

valkesh patel
  • 116
  • 11