1

I need to create image files on-the-fly in my controller with RMagick and send them to browser. Looks like it's very simple, but I can't find a way. I've tried just simply render them, but it fails due to data is binary. I've also tried to use send_data, but Padrino says it doesn't know about such method.

So, what have I missed? How can I solve this problem?

at8eqeq3
  • 165
  • 3

2 Answers2

5

Researching how to send files through Padrino controller I've found this question and it helps me to reach my goal.

The send_data method is a Sinatra request-method which has been removed in the version 1.0: https://github.com/sinatra/sinatra/blob/1.0/CHANGES#L108

I'm using the Padrino version 0.10.7 and my action have became into this:

get :screenshot, :provides => :jpg do
  ...
  File.open("path/to/file", "r").readlines
end
Rui Andrada
  • 246
  • 4
  • 9
3

according to sinatra api you don't need this anymore.

get :image, with: id, provides: :png do
  img = Image.find(params[:id])
  img.binary_data_or_so
end

basically is the same of:

get '/send_binarydata' do
  content_type 'image/png'
  \x01\x02\x03
end
DAddYE
  • 1,719
  • 11
  • 16