How to set content length by send_file

为君一笑 提交于 2019-12-10 15:39:23

问题


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

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


回答1:


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: The Header needs to be a string to work properly with some webservers.



来源:https://stackoverflow.com/questions/29485042/how-to-set-content-length-by-send-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!