Rac*_*Roy 4 ruby-on-rails ruby-on-rails-3
在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, :filename => "example.pdf", :type => "application/pdf" , :disposition => "inline")
| 归档时间: | 
 | 
| 查看次数: | 3582 次 | 
| 最近记录: |