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
eeb2c285
Unverified
Commit
eeb2c285
authored
Jun 16, 2023
by
Columbus
Committed by
GitHub
Jun 16, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix the issue of decoding a non-UTF-8 encoded file using UTF-8 encodi… (#378)
parent
673288d5
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
3 additions
and
1 deletion
+3
-1
file.py
api/controllers/console/datasets/file.py
+3
-1
No files found.
api/controllers/console/datasets/file.py
View file @
eeb2c285
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
}
...
...
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