Last active
August 29, 2015 14:07
-
-
Save atleastimtrying/6f63dc971f2b829561f7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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>)> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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