ruby image_proxy_controller.rb
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ruby image_proxy_controller.rb相关的知识,希望对你有一定的参考价值。
require 'net/http'
class ProfileController < ActionController::Base
def image
if params['id'] == 'john'
url = URI.parse('https://pbs.twimg.com/profile_images/1979976243/potato_300.jpg')
elsif params['id'] == 'cgarvis'
url = URI.parse('https://pbs.twimg.com/profile_images/1809634620/twitter-profile.png')
end
unless url == nil
image = Net::HTTP.get_response(url)
send_data image.body, type: image.content_type, disposition: 'inline'
else
send_file 'default_image_path.jpg'
end
end
end
require 'base64'
module ImageProxyHelper
def proxy_image_tag(source, options = nil
options[:src] = "/image_proxy/#{Base64.encode64(source)}"
tag("img", options)
end
end
require 'base64'
require 'net/http'
class ImageProxyController < ActionController::Base
def get
url = URI.parse(Base64.decode64(params[:url]))
image = Net::HTTP.get_response(url)
send_data image.body, type: image.content_type, disposition: 'inline'
end
end
以上是关于ruby image_proxy_controller.rb的主要内容,如果未能解决你的问题,请参考以下文章
Ruby运算符
Ruby 25 岁了!Ruby 之父说 Ruby 3 有望 3 倍提速
如何学习ruby?Ruby学习技巧分享
ruby Ruby脚本,看看是否用openssl编译了ruby
什么是ruby?
ruby和ruby ee