简体   繁体   中英

Display base64 encoded image in rails

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 #{}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM