# Problem sending files \> ~10KB using Active Resource

**URL:** <https://www.ruby-forum.com/t/problem-sending-files-10kb-using-active-resource/172508>\
**Category:** Rails\
**Created:** [July 22, 2009, 3:20pm UTC](https://www.ruby-forum.com/t/problem-sending-files-10kb-using-active-resource/172508 "2009-07-22T15:20:33Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![onomato](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/958977/32.png) [@onomato](https://www.ruby-forum.com/u/onomato)\
**Post date:** [July 22, 2009, 3:20pm UTC](https://www.ruby-forum.com/t/problem-sending-files-10kb-using-active-resource/172508/1 "2009-07-22T15:20:33Z")

</div>

Hey everybody,

scenario: frontend-server gets files from a form.file\_field and should  
send the filedata to a backend-server via (Hyper)ActiveResource!

I used the following code to access a method in a backend-server and  
send the filedata:

CampaignTopic.post(:icon\_attachments\_rebuild\_and\_save, :filedata =\>  
params[:campaign\_topic][:icon\_brand].read, :content\_type =\> params  
[:campaign\_topic][:icon\_brand].content\_typ )

This works fine for files less than ~10KB, otherwise a get a  
Errno::ECONNRESET  
An existing connection was forcibly closed by the remote host.

Application Trace:  
D:/dev/rubyonrails/ruby/lib/ruby/1.8/net/protocol.rb:175:in `write' D:/dev/rubyonrails/ruby/lib/ruby/1.8/net/protocol.rb:175:in`write0’  
D:/dev/rubyonrails/ruby/lib/ruby/1.8/net/protocol.rb:151:in `write' D:/dev/rubyonrails/ruby/lib/ruby/1.8/net/protocol.rb:166:in`writing’  
D:/dev/rubyonrails/ruby/lib/ruby/1.8/net/protocol.rb:150:in `write' D:/dev/rubyonrails/ruby/lib/ruby/1.8/net/http.rb:1583:in`write\_header’  
D:/dev/rubyonrails/ruby/lib/ruby/1.8/net/http.rb:1548:in  
`send_request_with_body' D:/dev/rubyonrails/ruby/lib/ruby/1.8/net/http.rb:1534:in`exec’  
D:/dev/rubyonrails/ruby/lib/ruby/1.8/net/http.rb:1057:in `request' D:/dev/rubyonrails/ruby/lib/ruby/1.8/net/http.rb:1046:in`request’  
D:/dev/rubyonrails/ruby/lib/ruby/1.8/net/http.rb:547:in `start' D:/dev/rubyonrails/ruby/lib/ruby/1.8/net/http.rb:1044:in`request’  
D:/dev/rubyonrails/ruby/lib/ruby/1.8/net/http.rb:854:in `post' D:/dev/rubyonrails/ruby/lib/ruby/gems/1.8/gems/activeresource-2.3.2/ lib/active_resource/connection.rb:149:in`send’  
D:/dev/rubyonrails/ruby/lib/ruby/gems/1.8/gems/activeresource-2.3.2/  
lib/active\_resource/connection.rb:149:in `request' D:/dev/rubyonrails/ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.2/lib/ active_support/core_ext/benchmark.rb:17:in`ms’  
D:/dev/rubyonrails/ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.2/lib/  
active\_support/core\_ext/benchmark.rb:10:in `realtime' D:/dev/rubyonrails/ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.2/lib/ active_support/core_ext/benchmark.rb:17:in`ms’  
D:/dev/rubyonrails/ruby/lib/ruby/gems/1.8/gems/activeresource-2.3.2/  
lib/active\_resource/connection.rb:149:in `request' D:/dev/rubyonrails/ruby/lib/ruby/gems/1.8/gems/activeresource-2.3.2/ lib/active_resource/connection.rb:134:in`post’  
D:/dev/rubyonrails/ruby/lib/ruby/gems/1.8/gems/activeresource-2.3.2/  
lib/active\_resource/custom\_methods.rb:61:in `post' D:/.../.../../.../.../../internal/trunk/app/controllers/ campaign_topics_controller.rb:92:in`create’

The Point is, that the request doesn’t contact the backend-method, so  
it’s the code posted above which causes the connection to be closed.  
Has anyone any idea what the problem might be?

thanks for help …

---

<div class="post-metadata">

**Author:** ![onomato](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/958977/32.png) [@onomato](https://www.ruby-forum.com/u/onomato)\
**Post date:** [July 22, 2009, 4:03pm UTC](https://www.ruby-forum.com/t/problem-sending-files-10kb-using-active-resource/172508/2 "2009-07-22T16:03:16Z")

</div>

What web server and how are you serving rails?

I have a caching media server built in rails and I ran into a couple  
problems that look identical to this. First I was on Apache2 with  
Ruby Enterprise Edition and Passenger Phusion using MySQL as the  
database.

In my case I needed to do two things. First give passenger phusion a  
LimitRequestBody value. I set this pretty high, well over 100MB  
(LimitRequestBody 104857600). You can just paste that into your  
virtual host config file for this site. Second I had to tell MySQL  
to use a larger maximum packet size. max\_allowed\_packet = 100M in the  
[mysqld] section of my.cnf.

I am no expert when it comes to how MySQL does its network connections  
and am not sure if the whole max packet thing should match the  
LimitRequestBody or not. I figured that the file and data being sent  
to MySQL was going to be smaller than the request that passenger  
handles so a little extra on the LimitRequestBody wouldn’t hurt.

After upgrading passenger to the latest version my Errno::ECONNRESET  
errors went away.
