@@ -196,4 +196,9 class ApplicationController < ActionController::Base | |||||
196 | end |
|
196 | end | |
197 | return tmp |
|
197 | return tmp | |
198 | end |
|
198 | end | |
|
199 | ||||
|
200 | # Returns a string that can be used as filename value in Content-Disposition header | |||
|
201 | def filename_for_content_disposition(name) | |||
|
202 | request.env['HTTP_USER_AGENT'] =~ %r{MSIE} ? ERB::Util.url_encode(name) : name | |||
|
203 | end | |||
199 | end |
|
204 | end |
@@ -21,7 +21,7 class AttachmentsController < ApplicationController | |||||
21 |
|
21 | |||
22 | def download |
|
22 | def download | |
23 | # images are sent inline |
|
23 | # images are sent inline | |
24 |
send_file @attachment.diskfile, :filename => @attachment.filename, |
|
24 | send_file @attachment.diskfile, :filename => filename_for_content_disposition(@attachment.filename), | |
25 | :type => @attachment.content_type, |
|
25 | :type => @attachment.content_type, | |
26 | :disposition => (@attachment.image? ? 'inline' : 'attachment') |
|
26 | :disposition => (@attachment.image? ? 'inline' : 'attachment') | |
27 | rescue |
|
27 | rescue |
@@ -67,7 +67,8 class DocumentsController < ApplicationController | |||||
67 | def download |
|
67 | def download | |
68 | @attachment = @document.attachments.find(params[:attachment_id]) |
|
68 | @attachment = @document.attachments.find(params[:attachment_id]) | |
69 | @attachment.increment_download |
|
69 | @attachment.increment_download | |
70 |
send_file @attachment.diskfile, :filename => @attachment.filename, |
|
70 | send_file @attachment.diskfile, :filename => filename_for_content_disposition(@attachment.filename), | |
|
71 | :type => @attachment.content_type | |||
71 | rescue |
|
72 | rescue | |
72 | render_404 |
|
73 | render_404 | |
73 | end |
|
74 | end |
@@ -42,7 +42,8 class VersionsController < ApplicationController | |||||
42 | def download |
|
42 | def download | |
43 | @attachment = @version.attachments.find(params[:attachment_id]) |
|
43 | @attachment = @version.attachments.find(params[:attachment_id]) | |
44 | @attachment.increment_download |
|
44 | @attachment.increment_download | |
45 |
send_file @attachment.diskfile, :filename => @attachment.filename, |
|
45 | send_file @attachment.diskfile, :filename => filename_for_content_disposition(@attachment.filename), | |
|
46 | :type => @attachment.content_type | |||
46 | rescue |
|
47 | rescue | |
47 | render_404 |
|
48 | render_404 | |
48 | end |
|
49 | end |
General Comments 0
You need to be logged in to leave comments.
Login now