Forum: Ruby on Rails download error: Cannot read file /images/header.gif

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Ruhul A. (Guest)
on 2007-02-22 09:18
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
Alex W. (Guest)
on 2007-02-22 12:34
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", ...)
tuhin (Guest)
on 2007-02-22 12:59
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", ...)

Thx for ur help.
Luigi (Guest)
on 2007-11-04 19:08
(Received via mailing list)
Hi,
do you know anyway to read a file with url?

Thank you

Luigi
Ruhul A. (Guest)
on 2007-11-04 19:25
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
This topic is locked and can not be replied to.