mirror of
https://gitee.com/dify_ai/dify.git
synced 2024-11-30 02:08:37 +08:00
fix encoding is none (#394)
This commit is contained in:
parent
9253f72dea
commit
b08c19d926
@ -143,7 +143,10 @@ class FilePreviewApi(Resource):
|
||||
with open(filepath, "rb") as fp:
|
||||
data = fp.read()
|
||||
encoding = chardet.detect(data)['encoding']
|
||||
if encoding:
|
||||
text = data.decode(encoding=encoding).strip() if data else ''
|
||||
else:
|
||||
text = data.decode(encoding='utf-8').strip() if data else ''
|
||||
|
||||
text = text[0:PREVIEW_WORDS_LIMIT] if text else ''
|
||||
return {'content': text}
|
||||
|
Loading…
Reference in New Issue
Block a user