Download resume with NET::HTTP

Discussion in 'Ruby' started by Alex Dj, May 9, 2008.

  1. Alex Dj

    Alex Dj Guest

    I'm wondering is there any way to do interrupt file download and then
    resume it from the same spot?
    The way I download file:

    Net::HTTP.start("server.com") { |http|
    response = http.request_get('/some/path') {|response|
    file_length = response['Content-Length']
    File.open('video.avi', 'w') {|f|
    response.read_body do |str| # read body now
    puts str.length
    f.write str
    end
    }
    }
    }

    I'm not using open-url as I found that open() method first downloads
    whole file and then starts to write it. Not for me....

    Cheers Alex
    --
    Posted via http://www.ruby-forum.com/.
     
    Alex Dj, May 9, 2008
    #1
    1. Advertising

  2. Alex Dj

    Marcelo Guest

    On Fri, May 9, 2008 at 8:18 AM, Alex Dj <> wrote:

    > Net::HTTP.start("server.com") { |http|
    > response = http.request_get('/some/path') {|response|


    create your request by hand:

    req = Net::HTTP::Get.new(path)
    req.range = ...

    In HTTP 1.1 range has the form "[lower]-[upper]", so "[lower]-" is
    valid. I'm not sure what range= takes, you get to try it :)

    Marcelo
     
    Marcelo, May 9, 2008
    #2
    1. Advertising

  3. Alex Dj

    Alex Dj Guest

    Thanks Marcelo,

    > In HTTP 1.1 range has the form "[lower]-[upper]", so "[lower]-" is
    > valid. I'm not sure what range= takes, you get to try it :)


    I found that its "Range: bytes=10000-", something like this. I wonder if
    I can use this header to download the same file from different mirrors
    i.e. have several
    req = Net::HTTP::Get.new(path)
    but with different ranges and write them to the same file with random
    access. Would it be a right technique for this idea?

    Thanks Alex

    --
    Posted via http://www.ruby-forum.com/.
     
    Alex Dj, May 9, 2008
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    3
    Views:
    1,007
  2. grzechor
    Replies:
    1
    Views:
    393
    Sumit Rajan
    Feb 3, 2006
  3. Alexander Vasilevsky

    WebRequest Resume Download

    Alexander Vasilevsky, Dec 20, 2007, in forum: ASP .Net
    Replies:
    1
    Views:
    583
    bruce barker
    Dec 20, 2007
  4. Gonzalo Garramuno

    Net::HTTP to resume file download

    Gonzalo Garramuno, Mar 31, 2006, in forum: Ruby
    Replies:
    0
    Views:
    150
    Gonzalo Garramuno
    Mar 31, 2006
  5. iMath
    Replies:
    0
    Views:
    126
    iMath
    Aug 7, 2013
Loading...

Share This Page