Ruby file_get_contents等价

deu*_*ces 11 ruby-on-rails image

我需要在我的rails程序中使用它,所以我可以获取图像内容然后base64它.我知道如何base64它但我只是不知道如何获得图像.谁知道怎么样?

jim*_*myi 19

编辑从外部URL检索:

PHP:

$image = file_get_contents("http://www.example.com/file.png");
Run Code Online (Sandbox Code Playgroud)

红宝石:

require 'net/http'
image = Net::HTTP.get_response(URI.parse("http://www.example.com/file.png")).body
Run Code Online (Sandbox Code Playgroud)