# Mongrel/XMLRPC For Ruby - Max Post Size

**URL:** <https://www.ruby-forum.com/t/mongrel-xmlrpc-for-ruby-max-post-size/114692>\
**Category:** Ruby\
**Created:** [September 17, 2007, 1:24pm UTC](https://www.ruby-forum.com/t/mongrel-xmlrpc-for-ruby-max-post-size/114692 "2007-09-17T13:24:14Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![BJ\_Dierkes](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/ebca7d/32.png) [@BJ\_Dierkes](https://www.ruby-forum.com/u/BJ_Dierkes)\
**Post date:** [September 17, 2007, 1:24pm UTC](https://www.ruby-forum.com/t/mongrel-xmlrpc-for-ruby-max-post-size/114692/1 "2007-09-17T13:24:14Z")

</div>

Hello List…

Ruby: 1.8.6  
Mongrel= 1.0.1

I have created a Ruby XMLRPC server (xmlrpc4r with mongrel) that is  
working great. Now I am working on posting large files that are  
base64 encoded and am having problems. The following is a sample of  
how the Mongrel/XMLRPC is setup and a sample handler:

======================================================================  
class XMLRPCHandler \< Mongrel::HttpHandler  
def initialize()  
@xmlrpc\_server = XMLRPC::BasicServer.new  
[…]  
end  
[…]  
end

@handler = XMLRPCHandler.new()

# @handler.xmlrpc\_server.add\_handler(‘file\_transfer’) do | token, source\_name, encoded\_source, source\_md5 | […] end

Note that The code within the handler is un-important… since the  
transfer fails before anything within the block is called. On the  
client side I have something like:

======================================================================  
if(File.exists?(self.source))  
source\_name = File.basename(source)  
encoded\_source = ‘’  
data = ‘’  
File.open(source) do |f|  
data = f.read  
end  
source\_md5 = Digest::MD5.hexdigest(data)  
encoded\_source = Base64.encode64(data)  
else  
raise ArgumentError, “source file [#{source}] does not exist!”  
end

# res = @server.call(‘file\_transfer’, @session.token, source\_name, encoded\_source, source\_md5)

When performing this call with a small text file, everything works as  
expected, md5sums match… etc. However, I am trying to transfer RPM  
files… the smallest of which is around 500K (not that big). Upon  
attempting to transfer I get the following error:

Sun Sep 16 17:50:52 -0500 2007: ERROR: undefined method `string’ for  
#\<File:/tmp/mongrel.16916.0\>

Like I said, everything works fine for a rather small text file… I  
then tried with just a simple file created from /dev/zero. At a size  
of 64K the file transfers fine. At 128K I again get the error above.

I’m wondering, is there some sort of limit that anyone can explain  
with regards to Mongrel and/or XMLRPC?

Any feedback is much appreciated.

Thank you.

Confidentiality Notice: This e-mail message (including any attached or  
embedded documents) is intended for the exclusive and confidential use  
of the  
individual or entity to which this message is addressed, and unless  
otherwise  
expressly indicated, is confidential and privileged information of  
Rackspace  
Managed Hosting. Any dissemination, distribution or copying of the  
enclosed  
material is prohibited. If you receive this transmission in error,  
please  
notify us immediately by e-mail at removed\_email\_address@domain.invalid, and delete the  
original message. Your cooperation is appreciated.

---

<div class="post-metadata">

**Author:** ![BJ\_Dierkes](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/ebca7d/32.png) [@BJ\_Dierkes](https://www.ruby-forum.com/u/BJ_Dierkes)\
**Post date:** [September 25, 2007, 11:05pm UTC](https://www.ruby-forum.com/t/mongrel-xmlrpc-for-ruby-max-post-size/114692/2 "2007-09-25T23:05:39Z")

</div>

> original message. Your cooperation is appreciated.

well i suggest you fix this 😛 no use for confidential notice when you  
post to public group.

---

<div class="post-metadata">

**Author:** ![BJ\_Dierkes](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/ebca7d/32.png) [@BJ\_Dierkes](https://www.ruby-forum.com/u/BJ_Dierkes)\
**Post date:** [September 17, 2007, 1:24pm UTC](https://www.ruby-forum.com/t/mongrel-xmlrpc-for-ruby-max-post-size/114692/3 "2007-09-17T13:24:47Z")

</div>

My apologies all. I have found where my issue is. Per the Rdoc for  
Mongrel::HttpRequest, if the POST size is over Const::MAX\_BODY, then  
the input is spit out to a tmp file, and then read in chunks:

“The HttpRequest.initialize method will convert any request that is  
larger than Const::MAX\_BODY into a Tempfile and use that as the body.  
Otherwise it uses a StringIO object. To be safe, you should assume it  
works like a file.”

This is fine, however I am actually overriding the  
HttpHandler.process method in order to log every API call:

# ====================================================================== if(base.config[‘log\_api\_calls’] == ‘true’) request\_xml = request.body.string […] end

The request.body.string call works fine for small transfers because  
it is a StringIO object. However, on larger files it is a File  
object… and it borks. Note the last line… ‘to be safe, you  
should assume it works like a file’. That is they key. 😉

On Sep 16, 2007, at 6:29 PM, BJ Dierkes wrote:

> ======================================================================  
> raise ArgumentError, “source file [#{source}] does not exist!”  
> that big). Upon attempting to transfer I get the following error:  
> I’m wondering, is there some sort of limit that anyone can explain  
> use of the

Confidentiality Notice: This e-mail message (including any attached or  
embedded documents) is intended for the exclusive and confidential use  
of the  
individual or entity to which this message is addressed, and unless  
otherwise  
expressly indicated, is confidential and privileged information of  
Rackspace  
Managed Hosting. Any dissemination, distribution or copying of the  
enclosed  
material is prohibited. If you receive this transmission in error,  
please  
notify us immediately by e-mail at removed\_email\_address@domain.invalid, and delete the  
original message. Your cooperation is appreciated.
