# Question about creating a link to download

**URL:** <https://www.ruby-forum.com/t/question-about-creating-a-link-to-download/163880>\
**Category:** Rails\
**Created:** [March 25, 2009, 7:54pm UTC](https://www.ruby-forum.com/t/question-about-creating-a-link-to-download/163880 "2009-03-25T19:54:39Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![bloc](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e8c25b/32.png) [@bloc](https://www.ruby-forum.com/u/bloc)\
**Post date:** [March 25, 2009, 7:54pm UTC](https://www.ruby-forum.com/t/question-about-creating-a-link-to-download/163880/1 "2009-03-25T19:54:39Z")

</div>

Hi Folks,

I’m new to Rails and working on a project where after the user logs in  
they can click on a link to download an exe file ( say for example the  
file is at [http://test.com/test.exe](http://test.com/test.exe)). I want to keep the link to the exe  
file hidden. What are the best ways to implement this step.

I was thinking about using the redirect to url but I have been getting  
an error saying that I cannot use two redirect’s in a function.

Also, I was thinking of using NET:HTTP to use http request but I have no  
idea how to implement this.

Thanks!!

---

<div class="post-metadata">

**Author:** ![bloc](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e8c25b/32.png) [@bloc](https://www.ruby-forum.com/u/bloc)\
**Post date:** [March 25, 2009, 8:05pm UTC](https://www.ruby-forum.com/t/question-about-creating-a-link-to-download/163880/2 "2009-03-25T20:05:24Z")

</div>

On Mar 25, 6:54 pm, Jay D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hi Folks,
> 
> I’m new to Rails and working on a project where after the user logs in  
> they can click on a link to download an exe file ( say for example the  
> file is athttp://test.com/test.exe). I want to keep the link to the exe  
> file hidden. What are the best ways to implement this step.
> 
> I was thinking about using the redirect to url but I have been getting  
> an error saying that I cannot use two redirect’s in a function.

redirect won’t hide the url

> Also, I was thinking of using NET:HTTP to use http request but I have no  
> idea how to implement this.

You could but it would block the mongrel for the entire time it took  
to download the file.

What’s not clear from your example is whether this file is on your  
server or somewhere else.

Fred

---

<div class="post-metadata">

**Author:** ![bloc](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e8c25b/32.png) [@bloc](https://www.ruby-forum.com/u/bloc)\
**Post date:** [March 25, 2009, 8:11pm UTC](https://www.ruby-forum.com/t/question-about-creating-a-link-to-download/163880/3 "2009-03-25T20:11:59Z")

</div>

Thanks for the reply.

The exe file is on another server.

Thanks!

Frederick C. wrote:

> On Mar 25, 6:54ï¿½pm, Jay D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > Hi Folks,
> > 
> > I’m new to Rails and working on a project where after the user logs in  
> > they can click on a link to download an exe file ( say for example the  
> > file is athttp://test.com/test.exe). I want to keep the link to the exe  
> > file hidden. What are the best ways to implement this step.
> > 
> > I was thinking about using the redirect to url but I have been getting  
> > an error saying that I cannot use two redirect’s in a function.
> 
> redirect won’t hide the url
> 
> > Also, I was thinking of using NET:HTTP to use http request but I have no  
> > idea how to implement this.
> 
> You could but it would block the mongrel for the entire time it took  
> to download the file.
> 
> What’s not clear from your example is whether this file is on your  
> server or somewhere else.
> 
> Fred

---

<div class="post-metadata">

**Author:** ![bloc](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e8c25b/32.png) [@bloc](https://www.ruby-forum.com/u/bloc)\
**Post date:** [March 25, 2009, 9:17pm UTC](https://www.ruby-forum.com/t/question-about-creating-a-link-to-download/163880/4 "2009-03-25T21:17:37Z")

</div>

On Mar 25, 7:11 pm, Jay D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Thanks for the reply.
> 
> The exe file is on another server.

OK. I was asking because if on the same server then things like X-Send-  
File or X-Accel-Redirect work very nicely. You certainly could use net/  
http to get the file and then send the response to the user although  
for anything but the smallest of files you’ll need to start sending  
the data before you have grabbed all of it (because otherwise the user  
will get bored or the browser will time you out) and I’m not sure  
there’s a nice way of doing that in rails.

Fred

---

<div class="post-metadata">

**Author:** ![bloc](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e8c25b/32.png) [@bloc](https://www.ruby-forum.com/u/bloc)\
**Post date:** [March 27, 2009, 12:50pm UTC](https://www.ruby-forum.com/t/question-about-creating-a-link-to-download/163880/5 "2009-03-27T12:50:31Z")

</div>

On Mar 26, 3:54 am, Jay D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> ## end
> 
> Posted viahttp://www.ruby-forum.com/.

Try using send\_file function 🙂  
[http://apidock.com/rails/ActionController/Streaming/send\_file](http://apidock.com/rails/ActionController/Streaming/send_file)

---

<div class="post-metadata">

**Author:** ![bloc](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e8c25b/32.png) [@bloc](https://www.ruby-forum.com/u/bloc)\
**Post date:** [March 27, 2009, 2:12pm UTC](https://www.ruby-forum.com/t/question-about-creating-a-link-to-download/163880/6 "2009-03-27T14:12:48Z")

</div>

Jay D. wrote:

> Hi Folks,
> 
> I’m new to Rails and working on a project where after the user logs in  
> they can click on a link to download an exe file ( say for example the  
> file is at [http://test.com/test.exe](http://test.com/test.exe)). I want to keep the link to the exe  
> file hidden. What are the best ways to implement this step.  
> You can make an expirable link Ã -la Rapidshare, and/or use  
> X-Accel-Redirect provided by Nginx, we use the latter to stream VOD.

---

<div class="post-metadata">

**Author:** ![bloc](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e8c25b/32.png) [@bloc](https://www.ruby-forum.com/u/bloc)\
**Post date:** [March 25, 2009, 9:54pm UTC](https://www.ruby-forum.com/t/question-about-creating-a-link-to-download/163880/7 "2009-03-25T21:54:41Z")

</div>

This is an example.

I tried this below code but it blocks mongrel until the whole file is  
read which is over 500 MB.

def download  
send\_data(open(‘[http://mirrors.gigenet.com/ubuntu/intrepid/ubuntu-8.10-desktop-i386.iso](http://mirrors.gigenet.com/ubuntu/intrepid/ubuntu-8.10-desktop-i386.iso)’).read,  
:filename =\> ‘ubuntu-8.10-desktop-i386.iso’ ,  
:type =\> ‘application/force-download’,  
:disposition =\> ‘attachment’)  
end
