I''m looking for a user to click a link to download an Mp3 file, but each way I try it loads the file in the browser to play. How can I force a download instead of playing directly in the browser? Thanks. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
This won''t be a popular answer, but you could map the mp3 mime-type on your server to application/octet-stream which the browser will not try to handle but it will prompt the open/save dialog. On 2/17/07, Bill <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > > I''m looking for a user to click a link to download an Mp3 file, but each > way I try it loads the file in the browser to play. > > How can I force a download instead of playing directly in the browser? > > Thanks. > > -- > Posted via http://www.ruby-forum.com/. > > > >-- Thanks, -Steve http://www.stevelongdo.com --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Feb 17, 2007, at 7:03 PM, Bill wrote:> I''m looking for a user to click a link to download an Mp3 file, but > each > way I try it loads the file in the browser to play. > > How can I force a download instead of playing directly in the browser?Add a Content-Disposition header: Content-Disposition: attachment; filename="foo.mp3" -pete -- (peter.royal|osi)@pobox.com - http://fotap.org/~osi
> Add a Content-Disposition header: > > Content-Disposition: attachment; filename="foo.mp3" > > -pete >Check out the send_file method, this will do it for you. You then create a controller to handle the presentation of the file. Below is an example, if its an image render inline, if not, then force a download. I''m using this with the attachment_fu plugin, which gives me methods like image? to show whether or not its an image. But, you could do something else. Basically, you send the full path to the file to the send_file method. You should then send the correct content-type and specify that the disposition is ''attachment'' class ViewFileController < ApplicationController # GET /assets/1 def show @asset = Asset.find(params[:id]) if @asset.image? inline else attachment end rescue ActiveRecord::RecordNotFound render :text => "return a file not found error here" end private def attachment send_file(@asset.full_filename, :filename => @asset.filename, :type => @asset.content_type, :disposition => ''attachment'', :streaming => true, :buffer_size => 4096) end def inline send_file(@asset.full_filename, :filename => @asset.filename, :type => @asset.content_type, :disposition => ''inline'') end end --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Why not give the user the option of both, though? Right-clicking to download or clicking to listen? I frequently middle-click to open mp3s in a background tab to listen to podcasts, music, etc. Instead of forcing your user to do things one way I think they''d appreciate having a choice. RSL On 2/17/07, Bill <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > > I''m looking for a user to click a link to download an Mp3 file, but each > way I try it loads the file in the browser to play. > > How can I force a download instead of playing directly in the browser? > > Thanks. > > -- > Posted via http://www.ruby-forum.com/. > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hi, In your controller, you can use send_data @mp3filecontent, :type => "put correct mime type here", :disposition => "attachment" Hope this helps, Regards, Oyku. On 18.Şub.2007, at 17:35, Russell Norris wrote:> Why not give the user the option of both, though? Right-clicking to > download or clicking to listen? I frequently middle-click to open > mp3s in a background tab to listen to podcasts, music, etc. Instead > of forcing your user to do things one way I think they''d appreciate > having a choice. > > RSL > > On 2/17/07, Bill <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote: > > I''m looking for a user to click a link to download an Mp3 file, but > each > way I try it loads the file in the browser to play. > > How can I force a download instead of playing directly in the browser? > > Thanks. > > -- > Posted via http://www.ruby-forum.com/. > > > > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---