加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – 在s3上使用redirect_to文件时.如何显示图像或

发布时间:2020-12-17 02:37:30 所属栏目:百科 来源:网络整理
导读:在Rails 3 AttachmentsController中,我有以下内容: def show attachment = Attachment.find_by_id(params[:id]) redirect_to(attachment.authenticated_url()) end 其中authenticated_url只是S3访问该文件的URL. 问题是该文件总是由浏览器下载.我想要发生的
在Rails 3 AttachmentsController中,我有以下内容:

def show
    attachment = Attachment.find_by_id(params[:id])
    redirect_to(attachment.authenticated_url())
  end

其中authenticated_url只是S3访问该文件的URL.

问题是该文件总是由浏览器下载.我想要发生的是,如果文件是image / pdf,浏览器可以渲染,在浏览器中显示文件,只下载非浏览器友好文件.

你以前见过这个吗?关于从哪里开始的任何想法?

谢谢

解决方法

send_file也可用于远程URL

file = open("http://cdn2.example.com/somefile.pdf")
send_file(file,:filename => "example.pdf",:type => "application/pdf",:disposition => "attachment")

这里将下载example.pdf.如果你想在浏览器中打开pdf,请使用它

file = open("http://cdn2.example.com/somefile.pdf")
send_file(file,:disposition => "inline")

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读