Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sending a binary stream with Sinatra 1.3

Tags:

ruby

sinatra

I'm building a Sinatra app that needs to send files to the user that it has just downloaded from elsewhere (essentially a proxy).

Whilst I have the bulk of it working, I cannot get Sinatra to send the correct filename as specified in my code. The code I'm using is:

get '/' do
  attachment file.name
  headers['Content-Type'] = file.content_type
  headers['Content-Disposition'] = 'attachment'
  file.body
end

(file.body is the contents of the file)

How can I get Sinatra to use the filename I want?

like image 831
Neil Middleton Avatar asked Mar 11 '26 08:03

Neil Middleton


1 Answers

headers["Content-Disposition"] = "attachment;filename=the_file.txt"
like image 84
Neil Middleton Avatar answered Mar 15 '26 01:03

Neil Middleton



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!