# Send a file, is it possible to do something like this?

**URL:** <https://www.ruby-forum.com/t/send-a-file-is-it-possible-to-do-something-like-this/137692>\
**Category:** Rails\
**Created:** [May 15, 2008, 11:35am UTC](https://www.ruby-forum.com/t/send-a-file-is-it-possible-to-do-something-like-this/137692 "2008-05-15T11:35:00Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![xdmx](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/x/53a042/32.png) [@xdmx](https://www.ruby-forum.com/u/xdmx)\
**Post date:** [May 15, 2008, 11:35am UTC](https://www.ruby-forum.com/t/send-a-file-is-it-possible-to-do-something-like-this/137692/1 "2008-05-15T11:35:00Z")

</div>

Hi, i’ve servers (not connected directly, only by internet), one with a  
rails app, and another with the big static files. The problem is, to  
access to one of them file you have to be logged, and when you click on  
a link the rails app will send you the file, but using the other server.  
Something like a redirect to download a file, but the real url of the  
file shouldn’t be displayed.

Simple example:  
I’m the user, i go to the site. I try to insert the url like  
[domain.com/download/3](http://domain.com/download/3) and the rails app tell me that i have to login, i  
login, i try another time and the app send me the file xyz.zip. Now,  
because i’m curious i do a properties on the current download to show  
where the file is stored, and i see [domain.com/download/3](http://domain.com/download/3), and not the  
real one which would be [domain2.com/files/xyz.com](http://domain2.com/files/xyz.com)

What do you think? Is it possible ? There is send\_file, but iirc it’s  
just for local files.  
Thanks

---

<div class="post-metadata">

**Author:** ![xdmx](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/x/53a042/32.png) [@xdmx](https://www.ruby-forum.com/u/xdmx)\
**Post date:** [May 15, 2008, 12:12pm UTC](https://www.ruby-forum.com/t/send-a-file-is-it-possible-to-do-something-like-this/137692/2 "2008-05-15T12:12:44Z")

</div>

On 15 May 2008, at 10:35, Xdmx X. wrote:

> What do you think? Is it possible ? There is send\_file, but iirc it’s  
> just for local files.

The browser has to know where to get the file from or else it can’t  
get it. I don’t think you can do this if the 2 servers are distinct  
(and don’t have any shared storage) unless you do something horrible  
like download it from the second server & forward it on byte by byte.

Fred

---

<div class="post-metadata">

**Author:** ![xdmx](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/x/53a042/32.png) [@xdmx](https://www.ruby-forum.com/u/xdmx)\
**Post date:** [May 15, 2008, 11:55pm UTC](https://www.ruby-forum.com/t/send-a-file-is-it-possible-to-do-something-like-this/137692/3 "2008-05-15T23:55:50Z")

</div>

I’ve just recently done something like this, without the having to log  
in.

I’ve created a downloads controller and a download model, the download  
model  
keeps track of what files are assigned to what IP and the users have to  
use  
the generated URL to get to their download. The cool thing is that it  
will  
not show the name of the file.

I’m using xsendfile to do this and going through apache. Another great  
thing  
is that, unlike send\_file, this won’t tie up a Rails request. Very handy  
if  
you’re downloading large files.

Here’s something that may get you going:

[http://john.guen.in/past/2007/4/17/send\_files\_faster\_with\_xsendfile/](http://john.guen.in/past/2007/4/17/send_files_faster_with_xsendfile/)

---

<div class="post-metadata">

**Author:** ![xdmx](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/x/53a042/32.png) [@xdmx](https://www.ruby-forum.com/u/xdmx)\
**Post date:** [May 16, 2008, 11:38am UTC](https://www.ruby-forum.com/t/send-a-file-is-it-possible-to-do-something-like-this/137692/4 "2008-05-16T11:38:52Z")

</div>

On 15 May 2008, at 22:54, Ryan B. (Radar) wrote:

> request. Very handy if you’re downloading large files.
> 
> Here’s something that may get you going:
> 
> [http://john.guen.in/past/2007/4/17/send\_files\_faster\_with\_xsendfile/](http://john.guen.in/past/2007/4/17/send_files_faster_with_xsendfile/)

The problem as i understand it is that the server with the files and  
the server with the rails app are physically distinct, so send\_file  
XSendfile doesn’t help.

Fred

---

<div class="post-metadata">

**Author:** ![xdmx](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/x/53a042/32.png) [@xdmx](https://www.ruby-forum.com/u/xdmx)\
**Post date:** [May 17, 2008, 4:02pm UTC](https://www.ruby-forum.com/t/send-a-file-is-it-possible-to-do-something-like-this/137692/5 "2008-05-17T16:02:57Z")

</div>

Frederick C. wrote:

> The problem as i understand it is that the server with the files and  
> the server with the rails app are physically distinct, so send\_file  
> XSendfile doesn’t help.

right, the server aren’t even in the same data center. i’ll hope in the  
future to move everything in the same one so i’ll use xsendfile 🙂  
Thanks anyway 🙂

---

<div class="post-metadata">

**Author:** ![xdmx](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/x/53a042/32.png) [@xdmx](https://www.ruby-forum.com/u/xdmx)\
**Post date:** [May 16, 2008, 12:19pm UTC](https://www.ruby-forum.com/t/send-a-file-is-it-possible-to-do-something-like-this/137692/6 "2008-05-16T12:19:35Z")

</div>

Oh foo I didn’t see that in the first line.
