ruby-on-rails – 如何通过send_file设置内容长度
发布时间:2020-12-17 04:02:14 所属栏目:百科 来源:网络整理
导读:我不知道如何通过send_file设置内容长度. 我检查了api,没有内容长度的参数. 解决方法 您可以为响应设置标题,例如: def download @file = Attachment.find params[:id] response.headers['Content-Length'] = @file.size.to_s send_file @file.path,:x_sendf
我不知道如何通过send_file设置内容长度.
我检查了api,没有内容长度的参数. 解决方法
您可以为响应设置标题,例如:
def download @file = Attachment.find params[:id] response.headers['Content-Length'] = @file.size.to_s send_file @file.path,:x_sendfile => true end 有关响应对象的更多信息,请参见official docs. P.S:Header需要是一个字符串才能与某些Web服务器一起正常工作. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |