![](/img/trans.png)
[英]How to post multipart/form-data from Angular to Nodejs Multer?
[英]Multer only parsing multipart/form-data from postman, not from actual form
我發現一年多前的這個問題與我的完全匹配,但沒有答案。
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"'
前端 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 開始,一切正常,但是在測試實際應用程序的表單時, req.body
的undefined
和req.file
的{}
任何見解將不勝感激!
.......... 我忘記在表單中設置字段的name
屬性。 現在工作正常。 事情總是簡單的,不是嗎?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.