I'm sending a base64 image to my controller and I'm saving it as it is. Now I need to display that image. This is what I'm doing to display but image is not showing up:
<img src="<%= Base64.decode64(@data_obj.first.desc) %>"/>
In order to encode I'm using this java-script function encodeURIComponent();
My encoded image format:
data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/........
You don't need to decode the base64
<img src="data:image/jpeg;base64,..." />
Should work
Using Helper: <%= image_tag "data:image/jpeg;base64,#{@image}" %>
Do not forget to put double quotes, because the interpolation using #{}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With