Fix file uploading in iOS (#8879)

* use * for file/* in ios

* add changeset

* add changeset

* tweak

---------

Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
This commit is contained in:
Hannah 2024-07-24 16:28:21 +01:00 committed by GitHub
parent ac132e3cbc
commit 67c08bfb9e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 21 additions and 0 deletions

View File

@ -0,0 +1,6 @@
---
"@gradio/upload": patch
"gradio": patch
---
fix:Fix file uploading in iOS

View File

@ -26,12 +26,25 @@
let file_data: FileData[];
let accept_file_types: string | null;
const get_ios = (): boolean => {
if (typeof navigator !== "undefined") {
const userAgent = navigator.userAgent.toLowerCase();
return userAgent.indexOf("iphone") > -1 || userAgent.indexOf("ipad") > -1;
}
return false;
};
$: ios = get_ios();
const dispatch = createEventDispatcher();
const validFileTypes = ["image", "video", "audio", "text", "file"];
const processFileType = (type: string): string => {
if (type.startsWith(".") || type.endsWith("/*")) {
return type;
}
if (ios && type === "file") {
return "*";
}
if (validFileTypes.includes(type)) {
return type + "/*";
}
@ -42,6 +55,8 @@
accept_file_types = null;
} else if (typeof filetype === "string") {
accept_file_types = processFileType(filetype);
} else if (ios && filetype.includes("file/*")) {
accept_file_types = "*";
} else {
filetype = filetype.map(processFileType);
accept_file_types = filetype.join(", ");