Skip to content

I just can't figured whats wrong why my codes below. I try to upload multiple files. #1275

Answered by IamLizu
Priya-Rathor asked this question in Q&A
Discussion options

You must be logged in to vote

Hi 👋

The issue you're experiencing is likely due to how the form-data is being sent to the server. When you use upload.fields([...]), each file field should have its corresponding file uploaded in the request. However, if any of the fields (file1, file2, file3, or file4) are missing or empty in the request, your code might interpret that as an error.

An easy fix would be using upload.array("images", 4) where images is the field for the form-data key and it can have up-to specified number of images, in this case 4. Meaning, you can add one or two or three or four image. Then you could just simply access the files with req.files.

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by IamLizu
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
2 participants
Converted from issue

This discussion was converted from issue #1274 on September 02, 2024 08:47.