I\'m trying to upload an image to PingFM. Their documentation says:
media – base64 encoded media data.
I can access this image via the URL.
Here's my solution:
1: Put this custom image_tag method into ApplicationHelper, and include ActiveSupport module
module ApplicationHelper
include ActiveSupport
def image_tag_base64(file_path, mime_type = 'image/jpeg', options = {})
image_tag("data:#{mime_type};base64,#{Base64.encode64(open(file_path) { |io| io.read })}", options)
end
end
2: Then, inside the view you want to use base64 encoded image use the method like this:
<%= image_tag_base64 @model.paperclip_attribute.path(:size), @model.paperclip_attribute.content_type, {class: 'responsive-img etc etc'} %>
3: DONE