附件的pdf预览添加inline请求头

dev_winse
SylorHuang 6 years ago
parent 7bd3bdc69d
commit b9de46e875

@ -15,7 +15,9 @@ class AttachmentsController < ApplicationController
update_downloads(@file)
redirect_to @file.cloud_url and return
end
send_file(absolute_path(local_path(@file)), filename: @file.filename, type: @file.content_type.presence || 'application/octet-stream')
pdf_attachment = params[:disposition] || "attachment"
send_file(absolute_path(local_path(@file)), filename: @file.filename,disposition: pdf_attachment, type: @file.content_type.presence || 'application/octet-stream')
update_downloads(@file)
end

@ -257,8 +257,8 @@ module ApplicationHelper
end
end
def download_url attachment
attachment_path(attachment)
def download_url attachment,options={}
attachment_path(attachment,options)
end
# 耗时:天、小时、分、秒

@ -8,5 +8,5 @@ json.downloads_count attachment.downloads_count
json.created_on attachment.created_on
# json.url attachment_path(attachment, type: 'history').gsub("/api","")
json.is_pdf attachment.is_history_pdf?
json.url attachment.is_history_pdf? ? attachment_path(attachment, type: 'history').gsub("/api","") : attachment_path(attachment, type: 'history')
json.url attachment.is_history_pdf? ? attachment_path(attachment, type: 'history',disposition:"inline") : attachment_path(attachment, type: 'history')
json.attachment_id attachment.attachment_id

@ -12,6 +12,6 @@ json.description attachment.description
json.downloads_count attachment.downloads_count
json.created_on attachment.created_on
json.is_pdf attachment.is_pdf?
json.url attachment.is_pdf? ? download_url(attachment).gsub("/api","") : download_url(attachment)
json.url attachment.is_pdf? ? download_url(attachment,disposition:"inline") : download_url(attachment)
# json.url download_url(attachment) unless attachment.locked?(@is_member)

@ -3,6 +3,6 @@ json.title attachment.title
json.filesize number_to_human_size attachment.filesize
json.description attachment.description
json.is_pdf attachment.is_pdf?
json.url attachment.is_pdf? ? download_url(attachment).gsub("/api","") : download_url(attachment)
json.url attachment.is_pdf? ? download_url(attachment,disposition:"inline") : download_url(attachment)
# json.url download_url(attachment)
json.set! :delete, delete.nil? ? true : delete if defined? delete

@ -2,5 +2,5 @@ json.id attachment.id
json.title attachment.title
json.filesize number_to_human_size(attachment.filesize)
json.is_pdf attachment.is_pdf?
json.url attachment.is_pdf? ? download_url(attachment).gsub("/api","") : download_url(attachment)
json.url attachment.is_pdf? ? download_url(attachment,disposition:"inline") : download_url(attachment)
json.created_on attachment.created_on

Loading…
Cancel
Save