Forum: Ruby on Rails send_file example code -- permissions?

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.
8dad1ec4d769734583f45fbbee5cd009?d=identicon&s=25 Jeff Pritchard (jeffpritchard)
on 2008-10-28 18:09
Hi,
I'm having trouble getting send_file to work.  I'm building a relatively
small csv file, and trying to let the user download it.

My action to do the download looks like this:

  def send_the_file
    @temp_download_file_path = session[:temp_file_path]
    send_file @temp_download_file_path,
                     :x_sendfile => true,
                     :type => 'text/csv',
                     :filename => "contacts.csv"
  end

No errors are generated.  Log says it is sending it.  I wind up with an
empty ( 1
byte) file on the other end.  I get the same results with and without
the "x_sendfile".

Any advice on where the file should reside on my server and how to set
the necessary permissions to allow send_file to get at it?  What else
could I be doing wrong?

Thanks for any additional help you guys can provide.

jp
8dad1ec4d769734583f45fbbee5cd009?d=identicon&s=25 Jeff Pritchard (jeffpritchard)
on 2008-10-31 02:49
Shameless bump.  I still really could use some help on this guys!  There
must be somebody out there who has used this.

thanks much,
jp
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2008-10-31 10:54
(Received via mailing list)
On Oct 31, 1:49 am, Jeff Pritchard <rails-mailing-l...@andreas-s.net>
wrote:
> Shameless bump.  I still really could use some help on this guys!  There
> must be somebody out there who has used this.
>
What's in the one byte?

send_file reads the file (in ruby) and spits the bytes out - the file
doesn't have to be anywhere in particular, but it does need to be
readable by your rails process. Have you tried sticking a breakpoint
in there and see if you can open/read the file ? (I'd forget about
x_sendfile for now)

Fred
A39970d780c506b26e9a8b71eda13df2?d=identicon&s=25 Walter McGinnis (Guest)
on 2008-11-01 03:52
(Received via mailing list)
Here's some example code that covers nginx, apache, or plain old
send_file:
http://github.com/kete/kete/tree/master/app/contro...

Works with 2.1, haven't tried it with 2.2 RC1 yet.

Hope it helps.

Cheers,
Walter

On Fri, Oct 31, 2008 at 2:49 PM, Jeff Pritchard <
8dad1ec4d769734583f45fbbee5cd009?d=identicon&s=25 Jeff Pritchard (jeffpritchard)
on 2008-11-01 23:41
Walter, this worked great.  Thanks a million!

jp


Walter McGinnis wrote:
> Here's some example code that covers nginx, apache, or plain old
> send_file:
> http://github.com/kete/kete/tree/master/app/contro...
>
> Works with 2.1, haven't tried it with 2.2 RC1 yet.
>
> Hope it helps.
>
> Cheers,
> Walter
>
> On Fri, Oct 31, 2008 at 2:49 PM, Jeff Pritchard <
A39970d780c506b26e9a8b71eda13df2?d=identicon&s=25 Walter McGinnis (Guest)
on 2008-11-02 07:41
(Received via mailing list)
Glad I could help. James Stradling was the guy that actually wrote
that particular bit of code.




On Nov 2, 2008, at 11:41 AM, Jeff Pritchard
<rails-mailing-list@andreas-s.net
This topic is locked and can not be replied to.