From 67265a58027ef1f9e4c0eb849a532f72eaebde48 Mon Sep 17 00:00:00 2001 From: Abubakar Abid Date: Thu, 3 Aug 2023 15:29:03 -0400 Subject: [PATCH] Allow supporting >1000 files in `gr.File()` and `gr.UploadButton()` (#5075) * allow supporting >1000 files * add changeset * Update client/js/src/client.ts --------- Co-authored-by: gradio-pr-bot --- .changeset/late-shrimps-tease.md | 6 ++++++ client/js/src/client.ts | 33 ++++++++++++++++++-------------- 2 files changed, 25 insertions(+), 14 deletions(-) create mode 100644 .changeset/late-shrimps-tease.md diff --git a/.changeset/late-shrimps-tease.md b/.changeset/late-shrimps-tease.md new file mode 100644 index 0000000000..dd94699d25 --- /dev/null +++ b/.changeset/late-shrimps-tease.md @@ -0,0 +1,6 @@ +--- +"@gradio/client": patch +"gradio": patch +--- + +fix:Allow supporting >1000 files in `gr.File()` and `gr.UploadButton()` diff --git a/client/js/src/client.ts b/client/js/src/client.ts index c4ac27ef5d..728e05b149 100644 --- a/client/js/src/client.ts +++ b/client/js/src/client.ts @@ -185,22 +185,27 @@ export function api_factory(fetch_implementation: typeof fetch) { if (token) { headers.Authorization = `Bearer ${token}`; } - - const formData = new FormData(); - files.forEach((file) => { - formData.append("files", file); - }); - try { - var response = await fetch_implementation(`${root}/upload`, { - method: "POST", - body: formData, - headers + const chunkSize = 1000; + const uploadResponses = []; + for (let i = 0; i < files.length; i += chunkSize) { + const chunk = files.slice(i, i + chunkSize); + const formData = new FormData(); + chunk.forEach((file) => { + formData.append("files", file); }); - } catch (e) { - return { error: BROKEN_CONNECTION_MSG }; + try { + var response = await fetch_implementation(`${root}/upload`, { + method: "POST", + body: formData, + headers + }); + } catch (e) { + return { error: BROKEN_CONNECTION_MSG }; + } + const output: UploadResponse["files"] = await response.json(); + uploadResponses.push(...output); } - const output: UploadResponse["files"] = await response.json(); - return { files: output }; + return { files: uploadResponses }; } async function client(