How to set send_file content length

I do not know how to set the content length to send_file.

I checked api, there is no content length parameter.

+4
source share
1 answer

You can set headers for the response, for example:

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

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

You can find more about the response object in official documents .

PS: The title should be a string to work correctly with some web servers.

+11
source

All Articles