batch uploaded files in blocks of 10 at a time
This commit is contained in:
@@ -10,6 +10,7 @@ import fs from "fs";
|
||||
import path from "path";
|
||||
|
||||
const FILENAME_ALLOWED = /^[A-Za-z0-9 ._\-:()—']+$/;
|
||||
const MAX_FILES_PER_UPLOAD_BATCH = 10;
|
||||
|
||||
function validateFilenameServer(originalFilename) {
|
||||
const name = path.basename(originalFilename || "");
|
||||
@@ -136,11 +137,32 @@ ApiProxy.post(async (req, res) => {
|
||||
}
|
||||
|
||||
try {
|
||||
const data = await uploadSingleFile(
|
||||
allowedFilesFormData,
|
||||
containerID,
|
||||
casefolderID
|
||||
);
|
||||
const allowedFileEntries = Object.entries(allowedFilesFormData);
|
||||
const data = [];
|
||||
|
||||
for (
|
||||
let index = 0;
|
||||
index < allowedFileEntries.length;
|
||||
index += MAX_FILES_PER_UPLOAD_BATCH
|
||||
) {
|
||||
const fileChunk = Object.fromEntries(
|
||||
allowedFileEntries.slice(
|
||||
index,
|
||||
index + MAX_FILES_PER_UPLOAD_BATCH
|
||||
)
|
||||
);
|
||||
|
||||
const uploadChunkResult = await uploadSingleFile(
|
||||
fileChunk,
|
||||
containerID,
|
||||
casefolderID
|
||||
);
|
||||
|
||||
if (Array.isArray(uploadChunkResult)) {
|
||||
data.push(...uploadChunkResult);
|
||||
}
|
||||
}
|
||||
|
||||
return respondSuccess(res, { data, invalidFiles });
|
||||
} catch (error) {
|
||||
consoleLogger(error);
|
||||
|
||||
Reference in New Issue
Block a user