# Download resume with NET::HTTP

**URL:** <https://www.ruby-forum.com/t/download-resume-with-net-http/137159>\
**Category:** Ruby\
**Created:** [May 9, 2008, 4:18pm UTC](https://www.ruby-forum.com/t/download-resume-with-net-http/137159 "2008-05-09T16:18:40Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![alexd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/96bed5/32.png) [@alexd](https://www.ruby-forum.com/u/alexd)\
**Post date:** [May 9, 2008, 4:18pm UTC](https://www.ruby-forum.com/t/download-resume-with-net-http/137159/1 "2008-05-09T16:18:40Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![alexd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/96bed5/32.png) [@alexd](https://www.ruby-forum.com/u/alexd)\
**Post date:** [May 9, 2008, 5:04pm UTC](https://www.ruby-forum.com/t/download-resume-with-net-http/137159/2 "2008-05-09T17:04:29Z")

</div>

On Fri, May 9, 2008 at 8:18 AM, Alex Dj [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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

---

<div class="post-metadata">

**Author:** ![alexd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/96bed5/32.png) [@alexd](https://www.ruby-forum.com/u/alexd)\
**Post date:** [May 9, 2008, 5:34pm UTC](https://www.ruby-forum.com/t/download-resume-with-net-http/137159/3 "2008-05-09T17:34:18Z")

</div>

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
