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
Use File.read and not File.new
require 'base64'
str = File.read("/path/to/file.mp3")
a = Base64.encode64(str)
puts a
require 'base64'
str = File.read("/path/to/file.mp3")
a = Base64.encode64(str.each_byte.to_a.join)
puts a
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.