首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用send_file设置内容类型

使用send_file设置内容类型
EN

Stack Overflow用户
提问于 2016-03-21 14:07:35
回答 2查看 1.7K关注 0票数 3

我需要发送一个具有特定内容类型(application/pkcs7-mime)的文件,用于苹果通用链接。我使用rails中的send_file函数,并添加:type作为参数,但类型总是text/plain

这是我的控制器:

代码语言:javascript
复制
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

我也试图像这样加起来:

代码语言:javascript
复制
send_file "#{Rails.root}/public/apple-app-site-association", :filename => "apple-app-site-association", :type => "application/pkcs7-mime" , :x_sendfile => true

然后手动设置如下:

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

有人能解释一下为什么这不管用吗?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2016-03-21 14:29:22

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

由于我的文件和我的路径都有相同的名称,所以始终没有到达apple_controller

所以我就改了文件名。

票数 1
EN

Stack Overflow用户

发布于 2016-03-21 14:15:47

有一个参数可以设置

file

UPDATE: Mime类型是否在config/initializers/mime_ type . is下注册?

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36133219

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档