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.
Jeff P. (Guest)
on 2008-10-28 19: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
Jeff P. (Guest)
on 2008-10-31 03: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
Frederick C. (Guest)
on 2008-10-31 11:54
(Received via mailing list)
On Oct 31, 1:49 am, Jeff P. <removed_email_address@domain.invalid>
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
Walter McGinnis (Guest)
on 2008-11-01 04: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 P. <
Jeff P. (Guest)
on 2008-11-02 00: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 P. <
Walter McGinnis (Guest)
on 2008-11-02 08: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 P.
<removed_email_address@domain.invalid
This topic is locked and can not be replied to.