Skip to content

Instantly share code, notes, and snippets.

@ashaw
Last active August 29, 2015 14:10
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ashaw/c006d711f4261892da94 to your computer and use it in GitHub Desktop.
Save ashaw/c006d711f4261892da94 to your computer and use it in GitHub Desktop.
class TilesController < ApplicationController
around_filter :up_s3
def tile_response(map)
respond_to do |format|
format.png {
send_data map.to_png, :content_type => Mime::Type.lookup_by_extension("png"), :disposition => "inline"
}
end
end
def up_s3
path = Rails.application.routes.recognize_path(request.env['PATH_INFO'])
path_str = "APPSLUG/#{Rails.env}/#{path[:slug]}/#{path[:v]}/#{path[:x]}/#{path[:y]}/#{path[:z]}.png"
obj = S3BUCKET.objects["#{path_str}"]
if obj.exists?
send_data obj.read, :content_type => Mime::Type.lookup_by_extension("png"), :disposition => "inline"
else
obj.write yield.first, :acl => :public_read, :content_type => "image/png"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment