upload large file
This commit is contained in:
parent
25eb25b9c3
commit
f8c9b93dad
@ -25,8 +25,20 @@ const ModalAddFile = ({ opened, handler, addFiles }) => {
|
|||||||
const handleSubmit = () => {
|
const handleSubmit = () => {
|
||||||
setIsLoading(true);
|
setIsLoading(true);
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
files.forEach((file) => formData.append('file', file));
|
const CHUNK_SIZE = 1 * 1024 * 1024; // 1MB chunks
|
||||||
API.files.upload(formData)
|
|
||||||
|
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) => {
|
.then((res) => {
|
||||||
if (res.status === 200) {
|
if (res.status === 200) {
|
||||||
validate(res.data);
|
validate(res.data);
|
||||||
|
Loading…
Reference in New Issue
Block a user