Rails: displaying an image from a blob field in a database

前端 未结 3 2005
后悔当初
后悔当初 2020-12-25 08:26

So, I managed to get an image blob into my MySQL database (there\'s a big hex number in the field), but I can\'t find any documentation on how to display the image in a rail

3条回答
  •  天涯浪人
    2020-12-25 09:25

    Because you mentioned "quick and dirty", I'll throw out this as an alternative-

    <%= ('' % Base64.encode64(@the_data)).html_safe %>
    

    I think this is closest to what you wanted to do. There's a few reasons that this code shouldn't be used as-is, but it's simple. I'd have to think more about how bad of an idea is it is to mark the whole thing as html_safe. Also, this wouldn't work in older versions of IE.

提交回复
热议问题