# Http post in chunks

**URL:** <https://www.ruby-forum.com/t/http-post-in-chunks/67819>\
**Category:** Rails\
**Created:** [September 7, 2006, 12:39am UTC](https://www.ruby-forum.com/t/http-post-in-chunks/67819 "2006-09-07T00:39:18Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![nuby2ruby](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/54ee81/32.png) [@nuby2ruby](https://www.ruby-forum.com/u/nuby2ruby)\
**Post date:** [September 7, 2006, 12:39am UTC](https://www.ruby-forum.com/t/http-post-in-chunks/67819/1 "2006-09-07T00:39:18Z")

</div>

This isn’t strictly a rails query. I have created a rails application  
that accepts post data on an action and I’m writing a ruby client that  
sends a file using HTTP::Post. However, the file is quite big and I want  
to display some kind of feedback on the send progress but I can’t work  
out any way to either write in chunks of a small size or to monitor the  
send progress in any other way. Is there a way I can do this?

Jeremy

---

<div class="post-metadata">

**Author:** ![nuby2ruby](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/54ee81/32.png) [@nuby2ruby](https://www.ruby-forum.com/u/nuby2ruby)\
**Post date:** [September 8, 2006, 2:22am UTC](https://www.ruby-forum.com/t/http-post-in-chunks/67819/2 "2006-09-08T02:22:29Z")

</div>

Well if anyone is interested heres how i solved it:

class VerboseStringIO \< StringIO  
def read(len = nil)  
progress = (pos.to\_f / length.to\_f) \* 100  
puts “Progress: #{progress}%”  
super(len)  
end  
end

data # string of data to post  
tio = VerboseStringIO.new(data)

req = Net::HTTP::Post.new("/controller/action")  
req.body\_stream = tio  
req.content\_length = data.length  
req.content\_type = “text/xml” #or whatever

http = Net::HTTP.new(“localhost”,3000)  
http.read\_timeout = 999  
response = http.start{|query| query.request req}

This should output:  
Progress: 1%  
Progress: 2%  
Progress: 3%

and so on so you can do whatever and show a progress bar or something.
