0

I have 2 Rails apps, App1 and App2.

App1 contains links to controller actions in App2 which in turn returns files (downloads), e.g.:

<%= link_to "Download Video", "http://app2/downloads/download_video", :target => "_bkank" %>

with "downloads" being and controller within App2 and "download_video" being an action of the "downloads" controller:

def download_video
    send_file  '/path/to/video/video.mp4', type: "video/mp4", :disposition => "inline"
end

Upon clicking the link, a new window (tab) is opened and the video is played in the window - this is a desired behavior .... my problem is, when looking t the logs, I see that the same GET request is sent 3 times - the first as HTML and then as / twice:

Started GET "/downloads/download_video" for ::1 at 2018-04-19 16:26:45 +0200
Processing by DownloadsController#download_video as HTML
Sent file /path/to/video/video.mp4 (0.2ms)
Completed 200 OK in 1ms


Started GET "/downloads/download_video" for ::1 at 2018-04-19 16:26:46 +0200
Processing by DownloadsController#download_video as */*
Sent file /path/to/video/video.mp4 (0.1ms)
Completed 200 OK in 1ms


Started GET "/downloads/download_video" for ::1 at 2018-04-19 16:26:46 +0200
Processing by DownloadsController#download_video as */*
Sent file /path/to/video/video.mp4 (0.1ms)
Completed 200 OK in 0ms

Could anyone let me know why this is happening and how I can prevent it?

Thanks, Jon.


@praga2050,

can you please post entire controller code ...

yes:

class DownloadsController < ApplicationController
    def download_video
        send_file  '/var/www/videos/video.mp4', type: "video/mp4", :disposition => "inline"
    end
end

@praga2050,

... try putting Rails.logger.debug with time stamp and see

yes:

Started GET "/downloads/download_video" for ::1 at 2018-04-20 13:59:42 +0200
Processing by DownloadsController#download_video as HTML
Log Date:2018-04-20T13:59:42+02:00
Sent file /path/to/video/video.mp4 (0.2ms)
Completed 200 OK in 1ms


Started GET "/downloads/download_video" for ::1 at 2018-04-20 13:59:42 +0200
Processing by DownloadsController#download_video as */*
Log Date:2018-04-20T13:59:42+02:00
Sent file /path/to/video/video.mp4 (0.2ms)
Completed 200 OK in 1ms


Started GET "/downloads/download_video" for ::1 at 2018-04-20 13:59:42 +0200
Processing by DownloadsController#download_video as */*
Log Date:2018-04-20T13:59:42+02:00
Sent file /path/to/video/video.mp4 (0.1ms)
Completed 200 OK in 1ms
Jon Williams
  • 77
  • 10

0 Answers0