Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
D
dify
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ai-tech
dify
Commits
66342741
Commit
66342741
authored
Jun 16, 2023
by
jyong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix the issue of decoding a non-UTF-8 encoded file using UTF-8
parent
ba1fa57d
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
2 deletions
+16
-2
file.py
api/controllers/console/datasets/file.py
+3
-1
requirements.txt
api/requirements.txt
+13
-1
No files found.
api/controllers/console/datasets/file.py
View file @
66342741
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
}
...
...
api/requirements.txt
View file @
66342741
...
...
@@ -31,3 +31,15 @@ celery==5.2.7
redis~=4.5.4
pypdf==3.8.1
openpyxl==3.1.2
requests~=2.28.2
pydantic~=1.10.8
SQLAlchemy~=1.4.48
Werkzeug~=2.3.4
click~=8.1.3
blinker~=1.6.2
numpy~=1.24.3
itsdangerous~=2.1.2
botocore~=1.29.146
alembic~=1.11.1
pytz~=2022.7.1
chardet~=5.1.0
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment