2016-03-21 127 views
1

我需要为Apple通用链接发送具有特定内容类型(application/pkcs7-mime)的文件。 我使用rails的send_file函数,并添加:type作为参数, 但类型始终为text/plain使用send_file设置内容类型

这里是我的控制器:

class AppleController < ApplicationController 
    def download_app_site_association 
    send_file "#{Rails.root}/public/apple-app-site-association", {:filename => "apple-app-site-association", :type => "application/pkcs7-mime" , :x_sendfile => true} 
    end 
end 

我也尝试添加这样的:

send_file "#{Rails.root}/public/apple-app-site-association", :filename => "apple-app-site-association", :type => "application/pkcs7-mime" , :x_sendfile => true 

和手动设置它像这样:

response.headers["Content-type"] = "application/pkcs7-mime" 
send_file "#{Rails.root}/public/apple-app-site-association", :filename => "apple-app-site-association", :x_sendfile => true 

谁能给我解释一下为什么这不起作用?

回答

1

我找到了解决方案。 的问题是,当我试图让mywebsite.com/apple-app-site-association,路由器首先搜索文件在#{Rails.root}/public/,然后在routes.rb

搜索路径作为我的文件,我的路线有相同的名称,apple_controller从未达到。

所以我只是改变了文件名。