请注意:我想用vanilla Node做到这一点。获取文件大小,上传和POST请求
我要上传与input type="file"
HTML标签的文件,并在同一个表单元素打一个提交按钮input type="submit"
并获得字节文件的大小,当我提出一个POST请求。
感谢
请注意:我想用vanilla Node做到这一点。获取文件大小,上传和POST请求
我要上传与input type="file"
HTML标签的文件,并在同一个表单元素打一个提交按钮input type="submit"
并获得字节文件的大小,当我提出一个POST请求。
感谢
类似下面应该工作:
var http = require('http');
var server = http.createServer(function(req, res) {
switch (req.url) {
case '/':
display_form(req, res);
break;
case '/upload':
show_bytes(req, res);
break;
default:
res.writeHead(404, {'content-Type': 'text/plain'});
res.write('not found');
res.end();
break;
}
});
server.listen(3000);
function display_form(req, res) {
res.writeHead(200, {'Content-Type': 'text/html'});
res.write(
'<form action="/upload" method="post" enctype="multipart/form-data">'+
'<input type="file" name="upload">'+
'<input type="submit" value="Submit">'+
'</form>'
);
res.end();
}
function show_bytes(req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.write(req.headers['content-length'] + ' bytes');
res.end();
}
你有没有尝试过任何东西! – dNitro
我不知道如何在纯Node.js中做到这一点,这就是为什么我向像你这样的专业人员提出这个问题的原因。 – JohnSnow
有谁知道?! – JohnSnow