# Strange send\_file problem

**URL:** <https://www.ruby-forum.com/t/strange-send-file-problem/77851>\
**Category:** Rails\
**Created:** [December 1, 2006, 12:29am UTC](https://www.ruby-forum.com/t/strange-send-file-problem/77851 "2006-12-01T00:29:54Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![minka](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/b38774/32.png) [@minka](https://www.ruby-forum.com/u/minka)\
**Post date:** [December 1, 2006, 12:29am UTC](https://www.ruby-forum.com/t/strange-send-file-problem/77851/1 "2006-12-01T00:29:54Z")

</div>

Or perhaps I am stumbling in newbie fashion (tho I have active\_merchant  
and a store site basically up and running in development mode - still I  
don’t feel I always understand what is going on.)

So, when I have  
send\_file(filename, :type =\> ‘application/x-zip’)  
redirect :action =\> index

the send\_file seems to hang, rather than complete. I’m deducing this  
because of errors that happen after the send\_file. When I try to  
navigate from the page containing ‘send\_file’ to another page, I get an  
error with a trace indicating that it has not been able to complete the  
redirect.

If the send\_file is followed by a ‘redirect :action =\> index’  
the redirect is never executed.

If I comment out the send\_file, the redirect is always executed.

What is the problem here? I’m stumped.  
thanks much!

Here is the relevant portion of the trace, see the download/redirect  
stuff:  
er.rb:173:in `start_thread' /usr/local/lib/ruby/1.8/webrick/server.rb:162:in`start\_thread’  
/usr/local/lib/ruby/1.8/webrick/server.rb:95:in `start' /usr/local/lib/ruby/1.8/webrick/server.rb:92:in`start’  
/usr/local/lib/ruby/1.8/webrick/server.rb:23:in `start' /usr/local/lib/ruby/1.8/webrick/server.rb:82:in`start’  
/usr/local/lib/ruby/gems/1.8/gems/rails-1.1.6/lib/webrick\_server.rb:67:in  
`dispatch' /usr/local/lib/ruby/gems/1.8/gems/rails-1.1.6/lib/commands/servers/webrick.rb:59 /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in`require’  
/usr/local/lib/ruby/gems/1.8/gems/activesupport-1.3.1/lib/active\_support/dependencies.rb:147:in  
`require' /usr/local/lib/ruby/gems/1.8/gems/rails-1.1.6/lib/commands/server.rb:30 /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in`require’  
/usr/local/lib/ruby/gems/1.8/gems/activesupport-1.3.1/lib/active\_support/dependencies.rb:147:in  
`require’  
script/server:3

```
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/base.rb:840:in
`redirect_to'
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/base.rb:854:in
`redirect_to'
app/controllers/products_controller.rb:167:in `download_vbj_product'
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/base.rb:941:in
`perform_action_without_filters'
```

---

<div class="post-metadata">

**Author:** ![minka](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/b38774/32.png) [@minka](https://www.ruby-forum.com/u/minka)\
**Post date:** [December 1, 2006, 7:51am UTC](https://www.ruby-forum.com/t/strange-send-file-problem/77851/2 "2006-12-01T07:51:45Z")

</div>

minka wrote:

> So, when I have  
> send\_file(filename, :type =\> ‘application/x-zip’)  
> redirect :action =\> index

This will get you into trouble. redirect is actually a reponse that  
just has a header that tells the browser to look in another url, and  
then the browser obeys. send\_file is also a response that sends binary  
data to the browser.

You cant send 2 reponses to only 1 request. So you can’t redirect and  
send a file in the same request. You need to find a different to do  
what you want here, because this code here will definately not work.

---

<div class="post-metadata">

**Author:** ![minka](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/b38774/32.png) [@minka](https://www.ruby-forum.com/u/minka)\
**Post date:** [December 1, 2006, 6:53pm UTC](https://www.ruby-forum.com/t/strange-send-file-problem/77851/3 "2006-12-01T18:53:08Z")

</div>

Getting rid of the redirect fixed it, thanks!  
note I couldn’t use render :action =\> index either, same problem there.

this group is a great help.

---

<div class="post-metadata">

**Author:** ![minka](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/b38774/32.png) [@minka](https://www.ruby-forum.com/u/minka)\
**Post date:** [December 1, 2006, 2:47pm UTC](https://www.ruby-forum.com/t/strange-send-file-problem/77851/4 "2006-12-01T14:47:15Z")

</div>

Alex W. wrote:

> minka wrote:
> 
> > So, when I have  
> > send\_file(filename, :type =\> ‘application/x-zip’)  
> > redirect :action =\> index
> 
> This will get you into trouble. redirect is actually a reponse that  
> just has a header that tells the browser to look in another url, and  
> then the browser obeys. send\_file is also a response that sends binary  
> data to the browser.
> 
> You cant send 2 reponses to only 1 request. So you can’t redirect and  
> send a file in the same request. You need to find a different to do  
> what you want here, because this code here will definately not work.

in my app i use this:

send\_file(filename, :type =\> ‘application/x-zip’)  
render :action =\> index
