Send_file 在浏览中打开文件而不是下载它 [英] Send_file open file in browse instead of download it

查看:66
本文介绍了Send_file 在浏览中打开文件而不是下载它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请告诉我这是如何工作的,因为我不明白......这是我的简单代码:

路线:

 get 'download' =>'pages#download'

我的行动:

def 下载send_file "#{Rails.root}/public/downloads/robots.zip", :type=>"application/zip"

和下载链接:

<%= link_to "download", download_path %>

所以,当我点击链接时,我得到了这个:

图片 http://joxi.ru/GrqvQ3xHlbaYmz.jpg

似乎浏览器正在尝试显示 zip 文件内容...但是当我从浏览器(或刷新页面)打开操作时,它工作正常.

为什么当我点击link_to生成的链接时它不起作用?

解决方案

添加 disposition: "inline" 而不是 disposition: "attachment" 对我有用.>

Please tell me how this works, because I don't understand... Here is my simple code:

Route:

 get 'download' =>'pages#download'

My action:

def download
  send_file "#{Rails.root}/public/downloads/robots.zip", :type=>"application/zip"

And download link:

<%= link_to "download", download_path %>

So, when i'm clicking on the link I get this:

Image http://joxi.ru/GrqvQ3xHlbaYmz.jpg

It seems like the browser is trying to show zip file content... But when I open the action from my browser (or refresh page) it's working fine.

Why doesn't it work when I click on the link generated by link_to?

解决方案

Adding disposition: "inline" instead of disposition: "attachment" worked for me.

这篇关于Send_file 在浏览中打开文件而不是下载它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆