Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
chenpangpang
open-webui
Commits
e61e1b07
"vscode:/vscode.git/clone" did not exist on "698934d9302cee7838135ffde7e5224b272e3545"
Commit
e61e1b07
authored
Apr 04, 2024
by
Timothy J. Baek
Browse files
fix: file upload issue
parent
62392aa8
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
3 additions
and
17 deletions
+3
-17
backend/apps/rag/main.py
backend/apps/rag/main.py
+3
-17
No files found.
backend/apps/rag/main.py
View file @
e61e1b07
...
...
@@ -448,25 +448,11 @@ def store_doc(
log
.
info
(
f
"file.content_type:
{
file
.
content_type
}
"
)
try
:
is_valid_filename
=
True
unsanitized_filename
=
file
.
filename
if
re
.
search
(
r
'[\\/:"\*\?<>|\n\t ]'
,
unsanitized_filename
)
is
not
None
:
is_valid_filename
=
False
filename
=
os
.
path
.
basename
(
unsanitized_filename
)
unvalidated_file_path
=
f
"
{
UPLOAD_DIR
}
/
{
unsanitized_filename
}
"
dereferenced_file_path
=
str
(
Path
(
unvalidated_file_path
).
resolve
(
strict
=
False
))
if
not
dereferenced_file_path
.
startswith
(
UPLOAD_DIR
):
is_valid_filename
=
False
file_path
=
f
"
{
UPLOAD_DIR
}
/
{
filename
}
"
if
is_valid_filename
:
file_path
=
dereferenced_file_path
else
:
raise
HTTPException
(
status_code
=
status
.
HTTP_400_BAD_REQUEST
,
detail
=
ERROR_MESSAGES
.
DEFAULT
(),
)
filename
=
file
.
filename
contents
=
file
.
file
.
read
()
with
open
(
file_path
,
"wb"
)
as
f
:
f
.
write
(
contents
)
...
...
@@ -477,7 +463,7 @@ def store_doc(
collection_name
=
calculate_sha256
(
f
)[:
63
]
f
.
close
()
loader
,
known_type
=
get_loader
(
file
.
filename
,
file
.
content_type
,
file_path
)
loader
,
known_type
=
get_loader
(
filename
,
file
.
content_type
,
file_path
)
data
=
loader
.
load
()
try
:
...
...
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