Skip to content

Instantly share code, notes, and snippets.

@atleastimtrying
Last active August 29, 2015 14:07
Show Gist options
  • Save atleastimtrying/6f63dc971f2b829561f7 to your computer and use it in GitHub Desktop.
Save atleastimtrying/6f63dc971f2b829561f7 to your computer and use it in GitHub Desktop.
[1] pry(#<LogoQuestion>)> url
=> "https://quizall_assets.s3.amazonaws.com/logo_questions/logos/000/000/001/original/shell.png?1412259727"
[2] pry(#<LogoQuestion>)> open(url,&:read)
URI::InvalidURIError: the scheme https does not accept registry part: quizall_assets.s3.amazonaws.com (or bad hostname?)
from /Users/anders/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/2.0.0/uri/generic.rb:214:in `initialize'
[3] pry(#<LogoQuestion>)>
def to_base64
begin
url = "https://quizall_assets.s3.amazonaws.com/logo_questions/logos/000/000/001/original/shell.png?1412259727"
#url = logo.url.sub! '//quizall_assets.s3.amazonaws.com/', '//s3.amazonaws.com/quizall_assets/'
b64 = Base64.encode64 open url, &:read
"data:image/png;base64,#{b64}".squish
rescue
""
end
end
#begin rescue end makes me sad
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment