Skip to content

Commit

Permalink
image upload fix (#7625)
Browse files Browse the repository at this point in the history
* image upload fix

* remove

* add changeset

* valid mimetype fix

* add changeset

---------

Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
  • Loading branch information
dawoodkhan82 and gradio-pr-bot committed Mar 6, 2024
1 parent 3d270d4 commit 8181695
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
6 changes: 6 additions & 0 deletions .changeset/common-months-guess.md
@@ -0,0 +1,6 @@
---
"@gradio/upload": patch
"gradio": patch
---

feat:image upload fix
12 changes: 9 additions & 3 deletions js/upload/src/Upload.svelte
Expand Up @@ -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)) {
Expand Down Expand Up @@ -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[];
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 8181695

Please sign in to comment.