For whatever reason, my send_file
doesn't actually prompt the user to download the file. However, If I right click on the link that triggers the send_file
action, then the user is prompted to download the file. It just doesn't prompt it on the same page as the link.
Not sure why this is happening, but here's my action in the controller:
# GET /consultants/agents/1/download_ssh_key
def download_ssh_key
@agent = Agent.find(params[:agent_id])
send_file "/home/shared/agent_#{@agent.uuid}"
end
When I click this link in the browser (without opening a new tab), this is what I see in the console:
I, [2019-10-05T22:40:47.713625 #3211] INFO -- : [1f170528-920b-4330-9d17-7107220235dd] Started GET "/consultants/agents/9/download_ssh_key" for 66.195.29.70 at 2019-10-05 22:40:47 -0500
I, [2019-10-05T22:40:47.714597 #3211] INFO -- : [1f170528-920b-4330-9d17-7107220235dd] Processing by Consultants::AgentsController#download_ssh_key as HTML
I, [2019-10-05T22:40:47.714673 #3211] INFO -- : [1f170528-920b-4330-9d17-7107220235dd] Parameters: {"agent_id"=>"9"}
D, [2019-10-05T22:40:47.717697 #3211] DEBUG -- : [1f170528-920b-4330-9d17-7107220235dd] Agent Load (0.5ms) SELECT `agents`.* FROM `agents` WHERE `agents`.`id` = 9 LIMIT 1
I, [2019-10-05T22:40:47.719397 #3211] INFO -- : [1f170528-920b-4330-9d17-7107220235dd] Sent file /home/shared/agent_22ac92d1 (0.3ms)
I, [2019-10-05T22:40:47.720488 #3211] INFO -- : [1f170528-920b-4330-9d17-7107220235dd] Completed 200 OK in 6ms (ActiveRecord: 0.5ms)
Am I missing something in my send_file
action that is supposed to trigger a download prompt? According to https://apidock.com/rails/ActionController/Streaming/send_file, the default option is to send it as an attachment (prompt for download) rather than loading the file in the browser.