优化文件读取编码解析
This commit is contained in:
parent
1b589bf562
commit
2c79a51e48
|
@ -26,6 +26,7 @@ class AttachmentsController < ApplicationController
|
||||||
accept_api_auth :show, :download, :upload
|
accept_api_auth :show, :download, :upload
|
||||||
require 'iconv'
|
require 'iconv'
|
||||||
|
|
||||||
|
|
||||||
def show
|
def show
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html {
|
format.html {
|
||||||
|
@ -41,6 +42,13 @@ class AttachmentsController < ApplicationController
|
||||||
render :action => 'diff'
|
render :action => 'diff'
|
||||||
elsif @attachment.is_text? && @attachment.filesize <= Setting.file_max_size_displayed.to_i.kilobyte
|
elsif @attachment.is_text? && @attachment.filesize <= Setting.file_max_size_displayed.to_i.kilobyte
|
||||||
@content = File.new(@attachment.diskfile, "rb").read
|
@content = File.new(@attachment.diskfile, "rb").read
|
||||||
|
# 编码为非 UTF-8先进行间接转码
|
||||||
|
# 部分unicode编码不直接支持转为 UTF-8
|
||||||
|
# modify by nwb
|
||||||
|
if @content.encoding.name != 'UTF-8'
|
||||||
|
@content = @content.force_encoding('GBK')
|
||||||
|
@content = @content.encode('UTF-8')
|
||||||
|
end
|
||||||
render :action => 'file'
|
render :action => 'file'
|
||||||
else
|
else
|
||||||
download
|
download
|
||||||
|
|
Loading…
Reference in New Issue