mirror of
https://github.com/gradio-app/gradio.git
synced 2024-11-27 01:40:20 +08:00
Fix: file_types
checking bug (#9678)
* Fix: file_types check * add changeset --------- Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
This commit is contained in:
parent
35bebf38eb
commit
a25a26e208
6
.changeset/thick-teeth-crash.md
Normal file
6
.changeset/thick-teeth-crash.md
Normal file
@ -0,0 +1,6 @@
|
||||
---
|
||||
"gradio": patch
|
||||
"gradio_client": patch
|
||||
---
|
||||
|
||||
fix:Fix: `file_types` checking bug
|
@ -689,17 +689,15 @@ def get_extension(encoding: str) -> str | None:
|
||||
|
||||
def is_valid_file(file_path: str, file_types: list[str]) -> bool:
|
||||
mime_type = get_mimetype(file_path)
|
||||
if mime_type is None:
|
||||
return False
|
||||
for file_type in file_types:
|
||||
if file_type == "file":
|
||||
return True
|
||||
if file_type.startswith("."):
|
||||
file_type = file_type.lstrip(".").lower()
|
||||
mime_type_split = mime_type.lower().split("/")
|
||||
if file_type == mime_type_split[1]:
|
||||
file_ext = Path(file_path).suffix.lstrip(".").lower()
|
||||
if file_type == file_ext:
|
||||
return True
|
||||
elif mime_type.startswith(f"{file_type}/"):
|
||||
elif mime_type is not None and mime_type.startswith(f"{file_type}/"):
|
||||
return True
|
||||
return False
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user