From f8c9b93daddb73341668d8d4c12d859cca09b004 Mon Sep 17 00:00:00 2001 From: grimhilt Date: Tue, 29 Aug 2023 21:18:03 +0200 Subject: [PATCH] upload large file --- src/pages/files/add.jsx | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/pages/files/add.jsx b/src/pages/files/add.jsx index a0827c1..9446e1c 100644 --- a/src/pages/files/add.jsx +++ b/src/pages/files/add.jsx @@ -25,8 +25,20 @@ const ModalAddFile = ({ opened, handler, addFiles }) => { const handleSubmit = () => { setIsLoading(true); const formData = new FormData(); - files.forEach((file) => formData.append('file', file)); - API.files.upload(formData) + const CHUNK_SIZE = 1 * 1024 * 1024; // 1MB chunks + + files.forEach((file, index) => { + const totalChunks = Math.ceil(file.size / CHUNK_SIZE); + + for (let chunkIndex = 0; chunkIndex < totalChunks; chunkIndex++) { + const start = chunkIndex * CHUNK_SIZE; + const end = Math.min(start + CHUNK_SIZE, file.size); + formData.append(`${files[index].name}`, file.slice(start, end), file.name); + } + }); + + API.files + .upload(formData) .then((res) => { if (res.status === 200) { validate(res.data);