Multer 仅解析来自邮递员的 multipart/form-data,而不是来自实际表单

Multer only parsing multipart/form-data from postman, not from actual form

我发现一年多前的 this question 与我的完全匹配,但没有答案。

邮递员卷曲:

curl --location --request POST 'http://127.0.0.1:8080/register' \
--header 'Cookie: connect.sid=s%3AZpgwFoDrgb23EX1DPXnehAB4REEoFFRS.s2%2B12XeRx9ugG2E6WtmGbxJmPv9y13unu2EdsUYdS8M' \
--form 'username="bob"' \
--form 'email="bob@bob.com"' \
--form 'password="password"' \
--form 'confirmPassword="password"' \
--form 'image=@"/C:/Users/<me>/Pictures/My Headshot.jpg"'

前端EJS:

<form action="/register" method="POST" id="register-form" enctype="multipart/form-data">
                <div class="input-group mb-3">
                    <label for="username" class="form-label input-group-text">Username</label>
                    <input type="text" class="form-control" id="username" placeholder="ILuvBooks101" value="<%= typeof username !== 'undefined' ? username: '' %>">
                </div>
                <div class="input-group mb-3">
                    <label for="email" class="form-label input-group-text">Email address</label>
                    <input type="email" class="form-control" id="email" placeholder="name@example.com" value="<%= typeof emailAddress !== 'undefined' ? emailAddress: '' %>">
                </div>
                <div class="input-group mb-3">
                    <label for="password" class="form-label input-group-text">Password</label>
                    <input type="password" class="form-control" id="password">
                </div>
                <div class="input-group mb-3">
                    <label for="confirmPassword" class="form-label input-group-text">Confirm Password</label>
                    <input type="password" class="form-control" id="confirmPassword">
                </div>
                <div class="input-group mb-3">
                    <label for="profilePicture" class="form-label input-group-text">Profile Picture</label>
                    <input class="form-control" type="file" id="image">
                </div>
                <button type="submit" class="btn btn-primary">Submit</button>
            </form>

从 Postman 那里,一切正常,但是在测试实际应用程序的表单时,我得到 undefined for req.file{} for req.body

如有任何见解,我们将不胜感激!

........我忘了设置表单中字段的name属性。现在工作正常。事情总是那么简单,不是吗?