# Download error: Cannot read file /images/header.gif

**URL:** <https://www.ruby-forum.com/t/download-error-cannot-read-file-images-header-gif/86435>\
**Category:** Rails\
**Created:** [February 22, 2007, 8:18am UTC](https://www.ruby-forum.com/t/download-error-cannot-read-file-images-header-gif/86435 "2007-02-22T08:18:57Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![tuhin\_cse99](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/a6a055/32.png) [@tuhin\_cse99](https://www.ruby-forum.com/u/tuhin_cse99)\
**Post date:** [February 22, 2007, 8:18am UTC](https://www.ruby-forum.com/t/download-error-cannot-read-file-images-header-gif/86435/1 "2007-02-22T08:18:57Z")

</div>

hi guys,  
I have to create a download link.As a newbie in ruby i googled for it  
and  
found the way for my problem.

def attachment  
send\_file(’/images/header.gif’,  
:filename =\> ‘My Filename!’,  
:type =\> ‘image/gif’,  
:disposition =\> ‘attachment’,  
:streaming =\> ‘true’,  
:buffer\_size =\> ‘4096’)  
end

but it show file download error: Cannot read file /images/header.gif  
My file location /images/header.gif  
what is the wrong?  
please mention a better way if any.  
please help me.

Amin

---

<div class="post-metadata">

**Author:** ![tuhin\_cse99](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/a6a055/32.png) [@tuhin\_cse99](https://www.ruby-forum.com/u/tuhin_cse99)\
**Post date:** [February 22, 2007, 11:34am UTC](https://www.ruby-forum.com/t/download-error-cannot-read-file-images-header-gif/86435/2 "2007-02-22T11:34:53Z")

</div>

Ruhul A. wrote:

> hi guys,  
> I have to create a download link.As a newbie in ruby i googled for it  
> and  
> found the way for my problem.
> 
> def attachment  
> send\_file(’/images/header.gif’,  
> :filename =\> ‘My Filename!’,  
> :type =\> ‘image/gif’,  
> :disposition =\> ‘attachment’,  
> :streaming =\> ‘true’,  
> :buffer\_size =\> ‘4096’)  
> end
> 
> but it show file download error: Cannot read file /images/header.gif  
> My file location /images/header.gif  
> what is the wrong?  
> please mention a better way if any.  
> please help me.
> 
> Amin

send\_file takes the full path to a file that is local on the webserver,  
not a url. It reads the data in that file and sends it back out to the  
browser. So what you most likely need is:

send\_file("#{RAILS\_ROOT}/public/images/header.gif", …)

---

<div class="post-metadata">

**Author:** ![tuhin\_cse99](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/a6a055/32.png) [@tuhin\_cse99](https://www.ruby-forum.com/u/tuhin_cse99)\
**Post date:** [February 22, 2007, 11:59am UTC](https://www.ruby-forum.com/t/download-error-cannot-read-file-images-header-gif/86435/3 "2007-02-22T11:59:49Z")

</div>

Alex W. wrote:

> send\_file takes the full path to a file that is local on the webserver,  
> not a url. It reads the data in that file and sends it back out to the  
> browser. So what you most likely need is:
> 
> send\_file("#{RAILS\_ROOT}/public/images/header.gif", …)

ï¼´ï½ˆï½˜ã€€ï½†ï½ï½’ã€€ï½•ï½’ã€€ï½ˆï½…ï½Œï½.

---

<div class="post-metadata">

**Author:** ![tuhin\_cse99](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/a6a055/32.png) [@tuhin\_cse99](https://www.ruby-forum.com/u/tuhin_cse99)\
**Post date:** [November 4, 2007, 6:08pm UTC](https://www.ruby-forum.com/t/download-error-cannot-read-file-images-header-gif/86435/4 "2007-11-04T18:08:20Z")

</div>

Hi,  
do you know anyway to read a file with url?

Thank you

Luigi

---

<div class="post-metadata">

**Author:** ![tuhin\_cse99](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/a6a055/32.png) [@tuhin\_cse99](https://www.ruby-forum.com/u/tuhin_cse99)\
**Post date:** [November 4, 2007, 6:25pm UTC](https://www.ruby-forum.com/t/download-error-cannot-read-file-images-header-gif/86435/5 "2007-11-04T18:25:22Z")

</div>

Luigi wrote:

> Hi,  
> do you know anyway to read a file with url?
> 
> Thank you
> 
> Luigi

Dear Luigi,

Use a library. Net::HTTP (in ‘net/http’) for http://… , Net::FTP (in  
‘net/ftp’) for ftp://…, etc

You have examples in the documentation of these libraries.

If not solved… please write agin.

Tuhin
