How to encode media in base64 given URL in Ruby

To encode a file:

require 'base64'
Base64.encode64(File.open("file_path", "rb").read)

To produce the file from the encoded string:

require 'base64'
encoded_string = Base64.encode64(File.open("file_path", "rb").read)

File.open(file_name_to_create, "wb") do |file|
    file.write(Base64.decode64(encoded_string))
end

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)