From be3680d4f33a1be96bac81bdf0e3a32f680f1cd9 Mon Sep 17 00:00:00 2001 From: guange <8863824@gmail.com> Date: Tue, 2 Jun 2015 15:43:03 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81doc=20docx=20pdf?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/attachments_controller.rb | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index b2364165b..68d83f974 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -69,12 +69,14 @@ class AttachmentsController < ApplicationController if candown || User.current.admin? || User.current.id == @attachment.author_id @attachment.increment_download if stale?(:etag => @attachment.digest) - req = RestClient.post 'http://192.168.80.107/Any2HtmlHandler.ashx', :txtDes => File.new(@attachment.diskfile, 'rb') - render :text => req.body - - # send_file @attachment.diskfile, :filename => filename_for_content_disposition(@attachment.filename), - # :type => detect_content_type(@attachment), - # :disposition => 'attachment' #inline can open in browser + if %w[doc docx pdf].any?{|word| @attachment.diskfile.downcase.end_with? word} + req = RestClient.post 'http://192.168.80.107/Any2HtmlHandler.ashx', :txtDes => File.new(@attachment.diskfile, 'rb') + render :text => req.body + else + send_file @attachment.diskfile, :filename => filename_for_content_disposition(@attachment.filename), + :type => detect_content_type(@attachment), + :disposition => 'attachment' #inline can open in browser + end end else