如何通过send_file设置内容长度 [英] How to set content length by send_file

查看:85
本文介绍了如何通过send_file设置内容长度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道如何通过send_file设置内容长度.

I don't know how to set content-length by send_file.

我检查了api,没有内容长度参数.

I checked the api, there's no content-length param.

推荐答案

您可以设置响应标题,例如:

You can set headers for response like:

def download
  @file = Attachment.find params[:id]

  response.headers['Content-Length'] = @file.size.to_s
  send_file @file.path, :x_sendfile => true
end

有关响应对象的更多信息,您可以在官方文档中找到

More info about response object you can find on official docs.

P.S:标头必须为字符串,才能与某些网络服务器正常工作.

P.S: The Header needs to be a string to work properly with some webservers.

这篇关于如何通过send_file设置内容长度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆