fix: improve file upload handling in prepare-request to use streaming (#5637)

* fix: improve file upload handling in prepare-request to use streaming
* feat: add unit tests

---------

Co-authored-by: Bijin Bruno <bijin@usebruno.com>
This commit is contained in:
Sanjai Kumar
2025-09-30 22:47:09 +05:30
committed by GitHub
parent 14966f6e6c
commit c7029d1cda
7 changed files with 222 additions and 26 deletions

View File

@@ -158,6 +158,22 @@ const validateName = (name) => {
);
};
/**
* Checks if a file is larger than a given threshold.
* @param {string} filePath - The path to the file.
* @param {number} threshold - The threshold in bytes. Default is 10MB.
* @returns {boolean} True if the file is larger than the threshold, false otherwise.
*/
const isLargeFile = (filePath, threshold = 10 * 1024 * 1024) => {
if (!isFile(filePath)) {
throw new Error(`File ${filePath} is not a file`);
}
const size = fs.statSync(filePath).size;
return size > threshold;
};
module.exports = {
exists,
isSymbolicLink,
@@ -173,5 +189,6 @@ module.exports = {
stripExtension,
getSubDirectories,
sanitizeName,
validateName
validateName,
isLargeFile
};