Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I render a base64-encoded image in Rails?

I have a base64-encoded JPG in my app, and I'd like to render that image as a JPG in a controller.

like image 560
Skilldrick Avatar asked Dec 27 '22 12:12

Skilldrick


1 Answers

I worked this out as soon as I asked the question. Assuming you have the base64 string in @image_data:

send_data Base64.decode64(@image_data),
  :type => 'image/jpeg', :disposition => 'inline'
like image 193
Skilldrick Avatar answered Jan 13 '23 13:01

Skilldrick