Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set content length by send_file

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

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

like image 428
Gabriel Tong Avatar asked Dec 09 '22 04:12

Gabriel Tong


1 Answers

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.

like image 176
rastasheep Avatar answered Jan 03 '23 00:01

rastasheep