Unverified Commit b08c19d9 authored by Jyong's avatar Jyong Committed by GitHub

fix encoding is none (#394)

parent 9253f72d
...@@ -143,7 +143,10 @@ class FilePreviewApi(Resource): ...@@ -143,7 +143,10 @@ class FilePreviewApi(Resource):
with open(filepath, "rb") as fp: with open(filepath, "rb") as fp:
data = fp.read() data = fp.read()
encoding = chardet.detect(data)['encoding'] encoding = chardet.detect(data)['encoding']
text = data.decode(encoding=encoding).strip() if data else '' 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 '' text = text[0:PREVIEW_WORDS_LIMIT] if text else ''
return {'content': text} return {'content': text}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment