mirror of
https://github.com/gradio-app/gradio.git
synced 2025-03-13 11:57:29 +08:00
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:
parent
ac132e3cbc
commit
67c08bfb9e
6
.changeset/eager-eagles-kick.md
Normal file
6
.changeset/eager-eagles-kick.md
Normal file
@ -0,0 +1,6 @@
|
||||
---
|
||||
"@gradio/upload": patch
|
||||
"gradio": patch
|
||||
---
|
||||
|
||||
fix:Fix file uploading in iOS
|
@ -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(", ");
|
||||
|
Loading…
x
Reference in New Issue
Block a user