Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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