diff --git a/.changeset/eager-eagles-kick.md b/.changeset/eager-eagles-kick.md new file mode 100644 index 0000000000000..63c8f2f45c001 --- /dev/null +++ b/.changeset/eager-eagles-kick.md @@ -0,0 +1,6 @@ +--- +"@gradio/upload": patch +"gradio": patch +--- + +fix:Fix file uploading in iOS diff --git a/js/upload/src/Upload.svelte b/js/upload/src/Upload.svelte index 69b935b7e293f..8e7d8c57dd8bb 100644 --- a/js/upload/src/Upload.svelte +++ b/js/upload/src/Upload.svelte @@ -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(", ");