# Sample code for doing a â€œchunkedâ€ webfile HTTP d ownload, and then stream to HTTP upload to anot

**URL:** <https://www.ruby-forum.com/t/sample-code-for-doing-a-a-oechunkeda-webfile-http-d-ownload-and-then-stream-to-http-upload-to-anot/179957>\
**Category:** Ruby\
**Created:** [December 8, 2009, 7:22pm UTC](https://www.ruby-forum.com/t/sample-code-for-doing-a-a-oechunkeda-webfile-http-d-ownload-and-then-stream-to-http-upload-to-anot/179957 "2009-12-08T19:22:43Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![greg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/71c47a/32.png) [@greg](https://www.ruby-forum.com/u/greg)\
**Post date:** [December 8, 2009, 7:22pm UTC](https://www.ruby-forum.com/t/sample-code-for-doing-a-a-oechunkeda-webfile-http-d-ownload-and-then-stream-to-http-upload-to-anot/179957/1 "2009-12-08T19:22:43Z")

</div>

Hi,

QUESTION: Does anyone have sample code that shows how to do an (a)  
chunked HTTP file download, and then (b) stream this into the HTTP  
uploading of this to another web application with a file upload  
controller?

BACKGROUND

- I’ve been trying to “stream” an existing webpage to a separate web  
application, using normal http request response approach.
- The issue I’m hitting is that there are some times when preparing  
the upload, whereby the source webserver where I’m sourcing the file  
from does NOT set the **content-length** , hence I can’t set this for  
the upload.
- My thinking is that to get around this the approach might be to use  
HTTP chunked mode (however I haven’t had any experience with this).  
I’m trying to avoid (a) having to download the file to disk first, but  
also (b) store the whole file up in memory before uploading
- The upload has to be a POST

thanks

---

<div class="post-metadata">

**Author:** ![greg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/71c47a/32.png) [@greg](https://www.ruby-forum.com/u/greg)\
**Post date:** [December 8, 2009, 7:37pm UTC](https://www.ruby-forum.com/t/sample-code-for-doing-a-a-oechunkeda-webfile-http-d-ownload-and-then-stream-to-http-upload-to-anot/179957/2 "2009-12-08T19:37:56Z")

</div>

On Tue, Dec 8, 2009 at 11:22 AM, Greg H. \<  
removed\_email\_address@domain.invalid\> wrote:

> Hi,
> 
> QUESTION: Does anyone have sample code that shows how to do an (a)  
> chunked HTTP file download, and then (b) stream this into the HTTP  
> uploading of this to another web application with a file upload  
> controller?

This shouldn’t be too difficult to do with either Rev or EventMachine,  
which  
both provide evented HTTP clients and servers.
