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