how can i convert bytes into base64 using ruby
ruby, ruby-on-rails
Solution
Use File.read and not File.new
TO ENCODE WITHOUT CONVERTING TO BYTES USE:
require 'base64'
str = File.read("/path/to/file.mp3")
a = Base64.encode64(str)
puts a
EDIT to convert to bytes first before encoding use:
require 'base64'
str = File.read("/path/to/file.mp3")
a = Base64.encode64(str.each_byte.to_a.join)
puts a
Problem
i want to convert bytes into the base64 format using ruby i tried this program but am not getting the proper output please help me ``` require 'base64' require 'open-uri' str = File.new("/path/to/file.mp3") a = Base64.encode64(str.each_byte{|byte| byte}) puts a ```