Forum: Ruby on Rails Download Movie through link

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.
5f772fb2216278f9bc34e9daa01c7821?d=identicon&s=25 Deepak Mahajan (deepruby)
on 2009-02-12 08:19
Hi,

I am storing movie data into db.
Now I want to access movie from db and create a link to allow download
movie.

But when I click on the link It simply open the movie player and does
not play the movie. player give error in movie file.

When I try to save_as link and save the movie file and play It work's
fine.

My code like:

=============== Controller
def download
      @movie = Movies.find(params[:file])
      @headers["Content-Type"] = "video/x-ms-wmv; charset=utf-8"
      render :text => @movie.file
end

=============== View

<%= link_to movie.filename, {:action => 'download', :id =>
movie.filename, :file => movie.id }%>

=======================


I just want to make a this link download on single click so it prompt
me.

Please let me know what can I do ? I really need some help.

Regards,
Deepak
80e4cb97cae5c8d745f72337d93fd8f2?d=identicon&s=25 MaD (Guest)
on 2009-02-12 08:43
(Received via mailing list)
if i understand correctly you can click that link, choose the option
'save as', download it to you hd and watch it. but you if you click
the link and choose 'open', your video player opens but doesn't show
any content. correct?

if so i don't think it's a problem with your rails app, but with your
operating system. because as i understand it, the file gets send
correctly. maybe try another video-player. are you able to open other
videos on the net (maybe upload one to a ftp and open it with your
browser)?
5f772fb2216278f9bc34e9daa01c7821?d=identicon&s=25 Deepak Mahajan (deepruby)
on 2009-02-12 09:07
MaD wrote:
> if i understand correctly you can click that link, choose the option
> 'save as', download it to you hd and watch it. but you if you click
> the link and choose 'open', your video player opens but doesn't show
> any content. correct?
>
> if so i don't think it's a problem with your rails app, but with your
> operating system. because as i understand it, the file gets send
> correctly. maybe try another video-player. are you able to open other
> videos on the net (maybe upload one to a ftp and open it with your
> browser)?

Hi MaD,

Yes your understanding is correct as u mentioned in first.
But I am able to open other videos on the net.

I am a new I don't know why this link not prompt me(to download or
open_with).
but when I make a link of stored file it prompt correctly. So I thought
some problem in my code.

Please help me.

Thanks
80e4cb97cae5c8d745f72337d93fd8f2?d=identicon&s=25 MaD (Guest)
on 2009-02-12 09:36
(Received via mailing list)
alright, then let's take a look at your code...
how does it work? do you store your files in a folder inside your
public-directory and filename points to that location? or do you store
your files inside your database? what exactly is Movie.file and
Movie.filename?

the following line throws me off (don't understand it):
  render :text => @movie.file

what could help is a look at send_file:
http://api.rubyonrails.org/classes/ActionControlle...

or even the improvement x_send_file:
  http://wiki.rubyonrails.org/rails/pages/HowtoSendFilesFast
B2d23c5b0b6de413d99702767d1d148d?d=identicon&s=25 Hitesh Rawal (hitesh)
on 2009-02-12 10:09
Deepak Mahajan wrote:
> MaD wrote:
>> if i understand correctly you can click that link, choose the option
>> 'save as', download it to you hd and watch it. but you if you click
>> the link and choose 'open', your video player opens but doesn't show
>> any content. correct?
>>
>> if so i don't think it's a problem with your rails app, but with your
>> operating system. because as i understand it, the file gets send
>> correctly. maybe try another video-player. are you able to open other
>> videos on the net (maybe upload one to a ftp and open it with your
>> browser)?
>
> Hi MaD,
>
> Yes your understanding is correct as u mentioned in first.
> But I am able to open other videos on the net.
>
> I am a new I don't know why this link not prompt me(to download or
> open_with).
> but when I make a link of stored file it prompt correctly. So I thought
> some problem in my code.
>
> Please help me.
>
> Thanks

As i understand you want application popup on link to download. if yes ?
then set content-type as application.

eg :  @headers['Content-Type'] = 'application/force-download'
5f772fb2216278f9bc34e9daa01c7821?d=identicon&s=25 Deepak Mahajan (deepruby)
on 2009-02-12 10:59
Hitesh Rawal wrote:
> Deepak Mahajan wrote:
>> MaD wrote:
>>> if i understand correctly you can click that link, choose the option
>>> 'save as', download it to you hd and watch it. but you if you click
>>> the link and choose 'open', your video player opens but doesn't show
>>> any content. correct?
>>>
>>> if so i don't think it's a problem with your rails app, but with your
>>> operating system. because as i understand it, the file gets send
>>> correctly. maybe try another video-player. are you able to open other
>>> videos on the net (maybe upload one to a ftp and open it with your
>>> browser)?
>>
>> Hi MaD,
>>
>> Yes your understanding is correct as u mentioned in first.
>> But I am able to open other videos on the net.
>>
>> I am a new I don't know why this link not prompt me(to download or
>> open_with).
>> but when I make a link of stored file it prompt correctly. So I thought
>> some problem in my code.
>>
>> Please help me.
>>
>> Thanks
>
> As i understand you want application popup on link to download. if yes ?
> then set content-type as application.
>
> eg :  @headers['Content-Type'] = 'application/force-download'

Thanks Hitesh and MaD,

I have changed the header content-type as 'application/force-download'.

and It works.
But when I click on open_with then It play movie on player as well as
download also.
even I remove force-download then also It download when I select
open_with.

can anybody have any idea?

Thanks
A10ba5e890803847d0ee59e178dfd8a3?d=identicon&s=25 Jeremy Olliver (Guest)
on 2009-02-12 21:18
(Received via mailing list)
I believe that the usual thing when sending files is to use the
webserver's filestreaming rather than rendering the file as text.

Try something like

send_file @movie.file_path, :disposition => :attachment

The disposition attachment option is actually set by default, but it
will provide the behavior you want of downloading, instead of trying
to open in the browser

On Feb 12, 10:59 pm, Deepak Mahajan <rails-mailing-l...@andreas-s.net>
This topic is locked and can not be replied to.