Strange Behavior with Multer #1282
Unanswered
codegeekery
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Strange Behavior with Multer File Upload Limit and Filename Validation
I'm encountering a strange issue with the file upload logic using Multer in my Node.js project. The setup is as follows:
ml-amz.csv
andml-wal.csv
The problem occurs when I try to upload a file with the incorrect filename (e.g.,
AMZ.csv
instead ofml-amz.csv
) and the file size exceeds the 5MB limit (e.g., 50MB).Expected Behavior:
When uploading a file that exceeds the size limit and has an incorrect filename, I expect the following:
"Invalid file name. Allowed: 'ml-amz.csv' or 'ml-wal.csv'"
.Actual Behavior:
When I upload a file that exceeds the size limit (e.g., 50MB) with an incorrect filename (e.g.,
AMZ.csv
):LIMIT_FILE_NAME
), the request just hangs and does not return any error.When I upload a file that is within the size limit (e.g., less than 5MB) but has an incorrect filename:
LIMIT_FILE_NAME
error with the appropriate error message:"Invalid file name. Allowed: 'ml-amz.csv' or 'ml-wal.csv'"
.This issue seems to be occurring when the file size exceeds the limit, and it's not correctly handling the filename validation error first.
Code Snippet:
Here is the relevant Multer configuration code:
Question:
Has anyone encountered a similar issue where neither file size validation (LIMIT_FILE_SIZE) nor filename validation (LIMIT_FILE_NAME) triggers? It seems that when the file size exceeds the limit and the filename is incorrect, the request just hangs without triggering any error. Is there a configuration issue or logic flaw here?
I would greatly appreciate any help on where I might be making an error in the logic or configuration. I’m not sure if this is a conflict in how Multer handles the validation or something else in my setup.
Any insights or suggestions would be greatly appreciated!
Beta Was this translation helpful? Give feedback.
All reactions