##// END OF EJS Templates
Image attachments are now sent inline to be viewed directly in the browser....
Jean-Philippe Lang -
r636:38e0c237a448
parent child
Show More
@@ -19,18 +19,13 class AttachmentsController < ApplicationController
19 layout 'base'
19 layout 'base'
20 before_filter :find_project, :check_project_privacy
20 before_filter :find_project, :check_project_privacy
21
21
22 # sends an attachment
23 def download
22 def download
24 send_file @attachment.diskfile, :filename => @attachment.filename
23 # images are sent inline
25 rescue
24 send_file @attachment.diskfile, :filename => @attachment.filename,
26 render_404
25 :type => @attachment.content_type,
27 end
26 :disposition => (@attachment.image? ? 'inline' : 'attachment')
28
29 # sends an image to be displayed inline
30 def show
31 render(:nothing => true, :status => 404) and return unless @attachment.diskfile =~ /\.(jpeg|jpg|gif|png)$/i
32 send_file @attachment.diskfile, :filename => @attachment.filename, :type => "image/#{$1}", :disposition => 'inline'
33 rescue
27 rescue
28 # in case the disk file was deleted
34 render_404
29 render_404
35 end
30 end
36
31
@@ -163,7 +163,7 module ApplicationHelper
163 rf = Regexp.new(filename, Regexp::IGNORECASE)
163 rf = Regexp.new(filename, Regexp::IGNORECASE)
164 # search for the picture in attachments
164 # search for the picture in attachments
165 if found = attachments.detect { |att| att.filename =~ rf }
165 if found = attachments.detect { |att| att.filename =~ rf }
166 image_url = url_for :controller => 'attachments', :action => 'show', :id => found.id
166 image_url = url_for :controller => 'attachments', :action => 'download', :id => found.id
167 "!#{align}#{image_url}!"
167 "!#{align}#{image_url}!"
168 else
168 else
169 "!#{align}#{filename}!"
169 "!#{align}#{filename}!"
@@ -84,6 +84,10 class Attachment < ActiveRecord::Base
84 container.is_a?(Project) ? container : container.project
84 container.is_a?(Project) ? container : container.project
85 end
85 end
86
86
87 def image?
88 self.filename =~ /\.(jpeg|jpg|gif|png)$/i
89 end
90
87 private
91 private
88 def sanitize_filename(value)
92 def sanitize_filename(value)
89 # get only the filename, not the whole path
93 # get only the filename, not the whole path
General Comments 0
You need to be logged in to leave comments. Login now