-
-
Notifications
You must be signed in to change notification settings - Fork 683
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
maxFiles options doesn't work #901
Comments
Temporary fix : let countFileUploaded = 0;
const form = formidable({
uploadDir: `${__dirname}/uploads`,
keepExtensions: true,
// maxFiles: 1,
filter: () => {
if (countFileUploaded === 1) return false;
countFileUploaded += 1;
return true;
}
}); |
Try again with version 3 |
It breaks my application with version 3, as I'm using CommonJS instead of ESModule. Will you add support for both CJS & ESM ? EDIT : I created another project for testing purposes. It doesn't seem to work perfectly though. Scenario 1 : const form = formidable({
uploadDir: `./uploads`,
maxFiles: 1
}); I try to upload 4 files, only 1 gets uploaded : Success. Scenario 2 : const form = formidable({
uploadDir: `./uploads`,
maxFiles: 2
}); I try to upload 4 files, only 1 gets uploaded : Failure. Scenario 3 : const form = formidable({
uploadDir: `./uploads`,
maxFiles: 3
}); I try to upload 4 files, only 2 get uploaded : Failure. Scenario 4 : const form = formidable({
uploadDir: `./uploads`,
maxFiles: 4
}); I try to upload 4 files, only 4 get uploaded : Success. Scenario 5 : const form = formidable({
uploadDir: `./uploads`,
maxFiles: 5
}); I try to upload 5 files, only 4 get uploaded : Failure. |
@bottom-up-ai ha, that looks very weird, definitely. As about CJS support... I don't want to, but unfortunately seems like we should and we will... |
If the number of files uploaded is greater than the max, the whole form is going to error. By the time that happens there maybe a lower number of files written to disk. The files that are ongoing are cancelled. That is why const form = formidable({ I try to upload 4 files, only 1 gets uploaded : Failure. As for scenario 5 I was not able to reproduce it. Please provide a repro case. |
To make formidable not error use the filter option instead. If it does not error it will not cancel ongoing write operations, which means you will have exactly the maximum files uploaded |
Support plan
Context
What are you trying to achieve or the steps to reproduce?
I try to limit the maxFiles option to 1, but when I upload 3 files, the 3 get uploaded in the corresponding folder.
What was the result you got?
3 files uploaded in folder
What result did you expect?
1 file uploaded in folder
The text was updated successfully, but these errors were encountered: