1

I'm facing a problem when showing base64 data please see below:

When I'm using for debugging:

<%= debug @photo %>

Showing like below image:

enter image description here

And this is correct.

When I'm using for the show:

<%= @photo %>

Showing like below image:

enter image description here

And this is not correct!

What I'm doing wrong?

faul
  • 35
  • 8
  • Your data isn't Base64 *except* when you call debug which uses YAML which uses Base64. – tadman Aug 01 '17 at 22:23
  • for debugging you might want to write to a file on the file system and verify that it can be decoded: `bundle exec rails console` : `photo = Photo.find(xxxx)` : `File.open('./tmp/photo1.xxxx, 'wb') { |f| f.write(Base64.decode64(photo)) }` then open that file from the rails tmp directory, if it is valid then use this technique to render it in an html page: https://stackoverflow.com/a/8499716/317989 – house9 Aug 01 '17 at 23:32

1 Answers1

1

This is not Base64 encoded data, you should try below code:

 require "base64"

 <%= Base64.encode64(@photo) %>

Learn more

fool-dev
  • 7,671
  • 9
  • 40
  • 54