[英]Multer only parsing multipart/form-data from postman, not from actual form
I found this question from over a year ago that exactly matches mine, but no answers.我发现一年多前的这个问题与我的完全匹配,但没有答案。
Postman curl: Postman curl:
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"'
front-end EJS:前端 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>
From Postman, everything works fine, but when testing the actual app's form, I get undefined
for req.file
and {}
for req.body
从 Postman 开始,一切正常,但是在测试实际应用程序的表单时,
req.body
的undefined
和req.file
的{}
Any insight would be appreciated!任何见解将不胜感激!
.......... I forgot to set the name
attribute of the fields in the form. .......... 我忘记在表单中设置字段的
name
属性。 Works fine now.现在工作正常。 It's always the simple things, isn't it?
事情总是简单的,不是吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.