Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby on Rails - External Image Url to Base64

is there anyway in Ruby on Rails to convert the image hosted in an image url (https://meo-fb-natal-dev.s3.amazonaws.com/participations/cropped/56658c5de2fc7116340000c0/635769180217506883-GD5A9264.jpg?1449495643) to Base64?

I've tried tons of things but none of them seem to work.

like image 725
Miguel Rebola Avatar asked Mar 09 '26 15:03

Miguel Rebola


1 Answers

What exactly is not working?

Here is an example:

$> 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..."
like image 115
Philidor Avatar answered Mar 12 '26 07:03

Philidor



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!