Display base64 encoded image in rails

前端 未结 2 615
慢半拍i
慢半拍i 2021-02-06 09:45

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:

相关标签:
2条回答
  • 2021-02-06 10:28

    You don't need to decode the base64

    <img src="data:image/jpeg;base64,..." />
    

    Should work

    0 讨论(0)
  • 2021-02-06 10:35

    Using Helper: <%= image_tag "data:image/jpeg;base64,#{@image}" %>
    Do not forget to put double quotes, because the interpolation using #{}

    0 讨论(0)
提交回复
热议问题