Skip to content

Commit

Permalink
Allow supporting >1000 files in gr.File() and gr.UploadButton() (#…
Browse files Browse the repository at this point in the history
…5075)

* allow supporting >1000 files

* add changeset

* Update client/js/src/client.ts

---------

Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
  • Loading branch information
abidlabs and gradio-pr-bot committed Aug 3, 2023
1 parent 2745075 commit 67265a5
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 14 deletions.
6 changes: 6 additions & 0 deletions .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()`
33 changes: 19 additions & 14 deletions client/js/src/client.ts
Expand Up @@ -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(
Expand Down

1 comment on commit 67265a5

@vercel
Copy link

@vercel vercel bot commented on 67265a5 Aug 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.