浏览代码

Fix the issue of decoding a non-UTF-8 encoded file using UTF-8 encodi… (#378)

tags/0.3.4
Columbus 2 年前
父节点
当前提交
eeb2c28526
没有帐户链接到提交者的电子邮件
共有 1 个文件被更改,包括 3 次插入1 次删除
  1. 3
    1
      api/controllers/console/datasets/file.py

+ 3
- 1
api/controllers/console/datasets/file.py 查看文件

@@ -1,6 +1,7 @@
import datetime
import hashlib
import tempfile
import chardet
import time
import uuid
from pathlib import Path
@@ -141,7 +142,8 @@ class FilePreviewApi(Resource):
# ['txt', 'markdown', 'md']
with open(filepath, "rb") as fp:
data = fp.read()
text = data.decode(encoding='utf-8').strip() if data else ''
encoding = chardet.detect(data)['encoding']
text = data.decode(encoding=encoding).strip() if data else ''

text = text[0:PREVIEW_WORDS_LIMIT] if text else ''
return {'content': text}

正在加载...
取消
保存