我需要发送一个具有特定内容类型(application/pkcs7-mime)的文件,用于苹果通用链接。我使用rails中的send_file函数,并添加:type作为参数,但类型总是text/plain。
这是我的控制器:
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有人能解释一下为什么这不管用吗?
发布于 2016-03-21 14:29:22
我找到了解决办法。问题是,当我试图获得mywebsite.com/apple-app-site-association时,路由器首先在#{Rails.root}/public/中搜索文件,然后在routes.rb中搜索路由。
由于我的文件和我的路径都有相同的名称,所以始终没有到达apple_controller。
所以我就改了文件名。
发布于 2016-03-21 14:15:47
有一个参数可以设置
file
UPDATE: Mime类型是否在config/initializers/mime_ type . is下注册?
https://stackoverflow.com/questions/36133219
复制相似问题