node.js 接收上传的文件

//limit 最大限制

app.use("/record/:where/:id", bodyParser.raw({"limit":"50mb"}), function (req, res, next) {
console.log("YES====");

let where = req.params.where;
let id = req.params.id;
//console.log("id==="+id);
let file = "";

let dirpath = "/Users/tmp/";

let dirname = "remote"+id+".webm";

let dirname2 = "local"+id+".webm";
//判断文件夹是否存在
if (!fs.existsSync("/Users/tmp")) {
fs.mkdirSync("/Users/tmp");
}

if (where === "remote") {
file = dirpath+dirname;
} else if (where === "local") {
file = dirpath + dirname2;
}else{
return;
}
fs.writeFile(file, req.body, "binary", function (err) {
if (err) {
console.log("localBlobs fail", err);
} else {
console.log("localBlobs success");
}
});

});

原文地址:https://www.cnblogs.com/fengyifengceaser/p/7366083.html