The send_data method haves just 4096 bytes of buffer used to stream the file.
A trick to expand the limit is change the 'content-length' on the HTTP Headers.
Example:
def index
@posts = Post.all
respond_to do |format|
format.html # index.html.erb
format.csv {
list = Post.csv_list(@posts)
send_data(list, { :type => "text/plain", :filename => "posts.csv", :disposition => "attachment" })
headers["Content-Length"] = list.to_s.length
}
end
end
The Ruby On Rails ActionController::Request headers method provides access to the request‘s HTTP headers. So you can use it to change the content length of the request.
If you have the path of the file you can use "File.size(path)", 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.
See you.