我尝试过很多东西,但似乎都没有。
答案 0 :(得分:7)
究竟什么不起作用?
以下是一个例子:
$> irb
>> require 'open-uri'
>> img = open("https://meo-fb-natal-dev.s3.amazonaws.com/participations/cropped/56658c5de2fc7116340000c0/635769180217506883-GD5A9264.jpg?1449495643")
# img variable is a tempfile with image
>> require 'base64'
>> Base64.encode64(img.read)
=> "/9j/4AAQSkZJRgABAQEASABIAAD/2wBDAAYEBQYFBAYGBQYHBwYIChAKCgkJ\nChQODwwQFxQYGBcUFhYaHSUfGhsjHBYWICwgIyYnKSopGR8tMC0oMCUoKSj/\n2wBDAQcHBwoIChMKChMoGhYaKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgo\nKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCj/wAARCAFTAoYDASIAAhEBAxEB/8QA\nHAAAAAcBAQAAAAAAAAAAAAAAAQIDBAUGBwAI/8QAShAAAgEDAgQEAwUGB..."
答案 1 :(得分:0)
你可以试试这个
url = "https://meo-fb-natal-dev.s3.amazonaws.com/participations/cropped/56658c5de2fc7116340000c0/635769180217506883-GD5A9264.jpg?1449495643"
ActiveSupport::Base64.encode64(open(url) { |io| io.read })