Browse Source

Don't force download of PDF (#22483).

Patch by Gregor Schmidt.

git-svn-id: http://svn.redmine.org/redmine/trunk@15409 e93f8b46-1217-0410-a6f0-8f06a7374b81
tags/3.3.0
Jean-Philippe Lang 8 years ago
parent
commit
3e776af806

+ 9
- 1
app/controllers/attachments_controller.rb View File

@@ -59,7 +59,7 @@ class AttachmentsController < ApplicationController
# images are sent inline
send_file @attachment.diskfile, :filename => filename_for_content_disposition(@attachment.filename),
:type => detect_content_type(@attachment),
:disposition => (@attachment.image? ? 'inline' : 'attachment')
:disposition => disposition(@attachment)
end
end

@@ -191,4 +191,12 @@ class AttachmentsController < ApplicationController
end
content_type.to_s
end

def disposition(attachment)
if attachment.is_image? || attachment.is_pdf?
'inline'
else
'attachment'
end
end
end

+ 9
- 1
app/controllers/repositories_controller.rb View File

@@ -173,7 +173,7 @@ class RepositoriesController < ApplicationController
send_opt = { :filename => filename_for_content_disposition(@path.split('/').last) }
send_type = Redmine::MimeType.of(@path)
send_opt[:type] = send_type.to_s if send_type
send_opt[:disposition] = (Redmine::MimeType.is_type?('image', @path) ? 'inline' : 'attachment')
send_opt[:disposition] = disposition(@path)
send_data @repository.cat(@path, @rev), send_opt
else
if !@entry.size || @entry.size <= Setting.file_max_size_displayed.to_i.kilobyte
@@ -441,4 +441,12 @@ class RepositoriesController < ApplicationController
)
graph.burn
end

def disposition(path)
if Redmine::MimeType.is_type?('image', @path) || Redmine::MimeType.of(@path) == "application/pdf"
'inline'
else
'attachment'
end
end
end

+ 4
- 0
app/models/attachment.rb View File

@@ -245,6 +245,10 @@ class Attachment < ActiveRecord::Base
self.filename =~ /\.(patch|diff)$/i
end

def is_pdf?
Redmine::MimeType.of(filename) == "application/pdf"
end

# Returns true if the file is readable
def readable?
File.readable?(diskfile)

Loading…
Cancel
Save