Abh*_*ikh 1 html javascript upload file node.js
我正在尝试使用Node.js服务器创建API来上传文件.我得到undefined
回应.
我正在关注本教程https://www.youtube.com/watch?v=UtfZ-5WKpro
Node.js的:
var express = require('express');
var app = express();
var bodyParser = require('body-parser');
app.use(bodyParser.json());
app.post("*", function(req, res) {
res.end(JSON.stringify(req.files) + "\n");
});
console.log("Server at 8080");
app.listen(8080);
Run Code Online (Sandbox Code Playgroud)
HTML
<html>
<head>
<form method="post"
enctype="multipart/form-data"
action="http://localhost:8080">
<input type="file" name="myimage" />
<input type="submit" name="submit" value="submit"/>
</form>
</head>
</html>
Run Code Online (Sandbox Code Playgroud)
点击提交后我收到了undefined
回复.
Run Code Online (Sandbox Code Playgroud)bodyParser.json()
...所以你已经为JSON格式的请求设置了一个解析器
Run Code Online (Sandbox Code Playgroud)enctype="multipart/form-data"
...但您没有制作JSON格式的请求.
请参阅body-parser的文档:
由于它们复杂且通常较大,因此不能处理多部分主体.对于多部分机构,您可能对以下模块感兴趣:
......后面是一系列建议.
选择一个可以处理多部分请求的模块,然后使用它来代替您当前的选择.
归档时间: |
|
查看次数: |
1671 次 |
最近记录: |