From: Tom Hughes Date: Thu, 21 Jun 2007 23:19:25 +0000 (+0000) Subject: Avoid reading traces and trace images into memory when sending them to X-Git-Tag: live~8374 X-Git-Url: https://git.openstreetmap.org/rails.git/commitdiff_plain/d781f42016767132eea7c7463549640d943c2910 Avoid reading traces and trace images into memory when sending them to the client, and make sure the MIME type is correct for trace files. --- diff --git a/app/controllers/trace_controller.rb b/app/controllers/trace_controller.rb index 478109eb0..1fb0b5c65 100644 --- a/app/controllers/trace_controller.rb +++ b/app/controllers/trace_controller.rb @@ -120,8 +120,10 @@ class TraceController < ApplicationController def data trace = Trace.find(params[:id]) - if trace.public? or (@user and @user == trace.user) - send_data(File.open("/home/osm/gpx/#{trace.id}.gpx",'r').read , :filename => "#{trace.id}.gpx", :type => 'text/plain', :disposition => 'inline') + if trace and (trace.public? or (@user and @user == trace.user)) + send_file(trace.trace_name, :filename => "#{trace.id}.gpx", :type => trace.mime_type, :disposition => 'attachment') + else + render :nothing, :status => 404 end end @@ -152,12 +154,20 @@ class TraceController < ApplicationController def picture trace = Trace.find(params[:id]) - send_data(trace.large_picture, :filename => "#{trace.id}.gif", :type => 'image/gif', :disposition => 'inline') if trace.public? or (@user and @user == trace.user) + if trace and (trace.public? or (@user and @user == trace.user)) + send_file(trace.large_picture_name, :filename => "#{trace.id}.gif", :type => 'image/gif', :disposition => 'inline') + else + render :nothing, :status => 404 + end end def icon trace = Trace.find(params[:id]) - send_data(trace.icon_picture, :filename => "#{trace.id}_icon.gif", :type => 'image/gif', :disposition => 'inline') if trace.public? or (@user and @user == trace.user) + if trace and (trace.public? or (@user and @user == trace.user)) + send_file(trace.icon_picture_name, :filename => "#{trace.id}_icon.gif", :type => 'image/gif', :disposition => 'inline') + else + render :nothing, :status => 404 + end end def api_details diff --git a/app/models/trace.rb b/app/models/trace.rb index ba255e85d..2d4e9ef8a 100644 --- a/app/models/trace.rb +++ b/app/models/trace.rb @@ -72,6 +72,10 @@ class Trace < ActiveRecord::Base "/home/osm/gpx/#{id}.gpx" end + def mime_type + return `file -bi #{trace_name}`.chomp + end + def to_xml_node el1 = XML::Node.new 'gpx_file' el1['id'] = self.id.to_s