<?xml version="1.0" encoding="UTF-8"?>
<post>
  <body>&lt;p&gt;The send_data method haves just 4096 bytes of buffer used to stream the file.&lt;/p&gt;
&lt;p&gt;A trick to expand the limit is change the 'content-length' on the HTTP Headers.&lt;/p&gt;
&lt;p&gt;Example:&lt;/p&gt;

&lt;pre&gt;&lt;span class=&quot;keyword&quot;&gt;def &lt;/span&gt;&lt;span class=&quot;method&quot;&gt;index&lt;/span&gt;&lt;br /&gt;  &lt;span class=&quot;attribute&quot;&gt;@posts&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;constant&quot;&gt;Post&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;ident&quot;&gt;all&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;  &lt;span class=&quot;ident&quot;&gt;respond_to&lt;/span&gt; &lt;span class=&quot;keyword&quot;&gt;do&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;ident&quot;&gt;format&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;|&lt;/span&gt;&lt;br /&gt;    &lt;span class=&quot;ident&quot;&gt;format&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;ident&quot;&gt;html&lt;/span&gt; &lt;span class=&quot;comment&quot;&gt;# index.html.erb&lt;/span&gt;&lt;br /&gt;    &lt;span class=&quot;ident&quot;&gt;format&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;ident&quot;&gt;csv&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;{&lt;/span&gt;&lt;br /&gt;      &lt;span class=&quot;ident&quot;&gt;list&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;constant&quot;&gt;Post&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;ident&quot;&gt;csv_list&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;attribute&quot;&gt;@posts&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;)&lt;/span&gt;&lt;br /&gt;      &lt;span class=&quot;ident&quot;&gt;send_data&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;ident&quot;&gt;list&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;symbol&quot;&gt;:type&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;text/plain&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;&amp;quot;,&lt;/span&gt; &lt;span class=&quot;symbol&quot;&gt;:filename&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;posts.csv&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;&amp;quot;,&lt;/span&gt; &lt;span class=&quot;symbol&quot;&gt;:disposition&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;attachment&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;&amp;quot;&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;})&lt;/span&gt;&lt;br /&gt;      &lt;span class=&quot;ident&quot;&gt;headers&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;[&amp;quot;&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;Content-Length&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;&amp;quot;]&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;ident&quot;&gt;list&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;ident&quot;&gt;to_s&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;ident&quot;&gt;length&lt;/span&gt;&lt;br /&gt;    &lt;span class=&quot;punct&quot;&gt;}&lt;/span&gt;&lt;br /&gt;  &lt;span class=&quot;keyword&quot;&gt;end&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;keyword&quot;&gt;end&lt;/span&gt; &lt;br /&gt;&lt;/pre&gt;

&lt;p&gt;The Ruby On Rails ActionController::Request headers method provides access to the request&#8216;s HTTP headers. So you can use it to change the content length of the request.&lt;/p&gt;
&lt;p&gt;If you have the path of the file you can use &quot;File.size(path)&quot;, but if the file is generated on the fly, you need to convert to string and use the length to know the file size in bytes.&lt;/p&gt;
&lt;p&gt;See you.&lt;/p&gt;</body>
  <created-at type="datetime">2009-04-13T18:00:22Z</created-at>
  <id type="integer">42</id>
  <permalink>buffer-size-on-send_data</permalink>
  <title>Buffer size on send_data</title>
  <updated-at type="datetime">2009-04-13T19:20:36Z</updated-at>
  <user-id type="integer">3</user-id>
</post>
