From ba6e9bab0c202b4f70e8b4532bb6560e1c90b0d3 Mon Sep 17 00:00:00 2001 From: Brian M Date: Thu, 29 Apr 2010 16:33:52 -0400 Subject: [PATCH] Andriod browsers are served files as attachments instead of inline. Haris test on his phone and the behavior now works like it previously did. [#20 state:resolved responsible:"Brian Michalski"] --- app/controllers/application_controller.rb | 6 ++++++ app/controllers/revisions_controller.rb | 8 +++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index e29f364..292fe16 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -5,6 +5,12 @@ class ApplicationController < ActionController::Base helper :all # include all helpers, all the time protect_from_forgery # See ActionController::RequestForgeryProtection for details + # Request from an Android? + def android_user_agent? + request.env["HTTP_USER_AGENT"] && request.env["HTTP_USER_AGENT"][/(Android)/] + end + + def redirect_back #if authorization fails, redirect back redirect_to :back diff --git a/app/controllers/revisions_controller.rb b/app/controllers/revisions_controller.rb index 1f488e2..4ab7f67 100644 --- a/app/controllers/revisions_controller.rb +++ b/app/controllers/revisions_controller.rb @@ -119,10 +119,16 @@ def download revision.document.bypass_auth do revision.document.increment!(:downloaded) end + + disposition = 'inline' + if android_user_agent? + disposition = 'attachment' + end + send_data revision.upload.file_contents(:original), :filename => revision.upload_file_name, :type => revision.upload_content_type, - :disposition => 'inline' + :disposition => disposition else redirect_back end