我不知道如何通过 send_file
设置内容长度。
我检查了 api,没有内容长度参数。
最佳答案
您可以为响应设置 header ,例如:
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 需要是一个字符串才能在某些网络服务器上正常工作。
关于ruby-on-rails - 如何通过 send_file 设置内容长度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29485042/