Neil Middleton
Neil Middleton

Reputation: 22240

Sending a binary stream with Sinatra 1.3

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?

Upvotes: 3

Views: 1479

Answers (1)

Neil Middleton
Neil Middleton

Reputation: 22240

headers["Content-Disposition"] = "attachment;filename=the_file.txt"

Upvotes: 5

Related Questions