我正在使用nodejs服务器端开发一个Web应用程序,并尝试将pdf文件从客户端发送到服务器。
客户端:
var files = new FormData();
var count = 0;
$('#tableSlideId tr').each(function() {
var inputForm = $(this).find("th:first").children();
file = inputForm[0].files[0];
files.append((count++).toString(),file);
});
$.ajax({
type: "POST",
url: "/sendFiles",
data: files,
contentType: false,
processData: false,
}).done(function(err){
var text ="";
if(err) {
text = "Upload FAILED! Retry ...";
} else {
text = "Upload SUCCES!";
}
alert(text);
});
我认为这在客户端是可行的。但如果我使用此循环,实际上则会这样:
for(var p of files)
console.log(p);
我正确地可视化了要发送到服务器的所有元素。
服务器端:
app.post('/sendFiles', function(req,res) {
console.log("--->",req.body);
res.end();
});
在服务器中,我实在不知道如何可视化我发送的数据,实际上req.body老是为空。
我的目标是从客户端加载一些pdf文件,发送到服务器,然后将它们存储在mySql dmbs中。