How to download video from url with fragments both on the server and on the client side

How to download video from url with pieces both on the server and on the client side.

  HttpURLConnection connection =
               (HttpURLConnection) url.openConnection();

       // Specify what portion of file to download.
       connection.setRequestProperty("Range",
               "bytes=" + downloaded + "-");

       // Connect to server.
       connection.connect();

       // Make sure response code is in the 200 range.
       if (connection.getResponseCode() / 100 != 2) {
           error();
       }

       // Check for valid content length.
       int contentLength = connection.getContentLength();
       if (contentLength < 1) {
           error();
       }

 /* Set the size for this download if it
    hasn't been already set. */
       if (size == -1) {
           size = contentLength;
           stateChanged();
       }

       // Open file and seek to the end of it.

     File  f = new File("/sdcard/Sample");
       if(f.exists())
       {

       }else
       {
           f.mkdir();
       }

       file = new RandomAccessFile(f.getAbsolutePath()+"/"+getFileName(url), "rw");
       file.seek(downloaded);

       stream = connection.getInputStream();

here i want to upload the file as pieces ... if the pieces coming from the server and my client, I need to download and merge this full video file

+3
source share
1 answer

Assuming you are using HTTP for download, you will want to use the HTTP HEAD http and RANGE http headers.

HEAD will give you the file size (if available), and then RANGE allows you to load a range of bytes.

, , . , .

SO fooobar.com/questions/1483113/...

0

All Articles