Commit 38e0c237 authored by Jean-Philippe Lang's avatar Jean-Philippe Lang

Image attachments are now sent inline to be viewed directly in the browser.

git-svn-id: http://redmine.rubyforge.org/svn/trunk@642 e93f8b46-1217-0410-a6f0-8f06a7374b81
parent c4239a4f
...@@ -19,18 +19,13 @@ class AttachmentsController < ApplicationController ...@@ -19,18 +19,13 @@ class AttachmentsController < ApplicationController
layout 'base' layout 'base'
before_filter :find_project, :check_project_privacy before_filter :find_project, :check_project_privacy
# sends an attachment
def download def download
send_file @attachment.diskfile, :filename => @attachment.filename # images are sent inline
rescue send_file @attachment.diskfile, :filename => @attachment.filename,
render_404 :type => @attachment.content_type,
end :disposition => (@attachment.image? ? 'inline' : 'attachment')
# sends an image to be displayed inline
def show
render(:nothing => true, :status => 404) and return unless @attachment.diskfile =~ /\.(jpeg|jpg|gif|png)$/i
send_file @attachment.diskfile, :filename => @attachment.filename, :type => "image/#{$1}", :disposition => 'inline'
rescue rescue
# in case the disk file was deleted
render_404 render_404
end end
......
...@@ -163,7 +163,7 @@ module ApplicationHelper ...@@ -163,7 +163,7 @@ module ApplicationHelper
rf = Regexp.new(filename, Regexp::IGNORECASE) rf = Regexp.new(filename, Regexp::IGNORECASE)
# search for the picture in attachments # search for the picture in attachments
if found = attachments.detect { |att| att.filename =~ rf } if found = attachments.detect { |att| att.filename =~ rf }
image_url = url_for :controller => 'attachments', :action => 'show', :id => found.id image_url = url_for :controller => 'attachments', :action => 'download', :id => found.id
"!#{align}#{image_url}!" "!#{align}#{image_url}!"
else else
"!#{align}#{filename}!" "!#{align}#{filename}!"
......
...@@ -84,6 +84,10 @@ class Attachment < ActiveRecord::Base ...@@ -84,6 +84,10 @@ class Attachment < ActiveRecord::Base
container.is_a?(Project) ? container : container.project container.is_a?(Project) ? container : container.project
end end
def image?
self.filename =~ /\.(jpeg|jpg|gif|png)$/i
end
private private
def sanitize_filename(value) def sanitize_filename(value)
# get only the filename, not the whole path # get only the filename, not the whole path
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment