image upload fix (#7625)

* image upload fix

* remove

* add changeset

* valid mimetype fix

* add changeset

---------

Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
This commit is contained in:
Dawood Khan 2024-03-06 12:00:49 -05:00 committed by GitHub
parent 3d270d43f9
commit 8181695e70
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 15 additions and 3 deletions

View File

@ -0,0 +1,6 @@
---
"@gradio/upload": patch
"gradio": patch
---
feat:image upload fix

View File

@ -28,7 +28,7 @@
const dispatch = createEventDispatcher();
const validFileTypes = ["image", "video", "audio", "text", "file"];
const processFileType = (type: string): string => {
if (type.startsWith(".")) {
if (type.startsWith(".") || type.endsWith("/*")) {
return type;
}
if (validFileTypes.includes(type)) {
@ -116,7 +116,13 @@
uploaded_file_extension: string,
uploaded_file_type: string
): boolean {
if (!file_accept || file_accept === "*" || file_accept === "file/*") {
if (
!file_accept ||
file_accept === "*" ||
file_accept === "file/*" ||
(Array.isArray(file_accept) &&
file_accept.some((accept) => accept === "*" || accept === "file/*"))
) {
return true;
}
let acceptArray: string[];
@ -145,7 +151,7 @@
const file_extension = "." + file.name.split(".").pop();
if (
file_extension &&
is_valid_mimetype(filetype, file_extension, file.type)
is_valid_mimetype(accept_file_types, file_extension, file.type)
) {
return true;
}