我必须创建一个上传功能,管理员可以为特定用户上传报告。
我可以访问此数据
当管理员上传报告时,我想创建一个目录(如果尚不存在)
var location = __dirname + '/../../public/' + USERID + 'reports/' + filename;
我一直遵循this tutorial上传文件,所以这是我的代码
function uploadReport(req, res) {
var fstream;
var location = __dirname + '/../../public/reports/' + filename;
if (req.busboy) {
req.busboy.on('file', function (fieldname, file, filename, encoding, mimetype) {
fstream = fs.createWriteStream(location);
file.pipe(fstream);
fstream.on('close', function () {
console.log('file ' + filename + ' uploaded');
});
});
req.busboy.on('finish', function () {
res.json({
success: true
});
});
req.pipe(req.busboy);
}
}
这是我从前端发送的邮件
------WebKitFormBoundaryvS6HEnoxsgpmx646
Content-Disposition: form-data; name="participant"
1
------WebKitFormBoundaryvS6HEnoxsgpmx646
Content-Disposition: form-data; name="type"
1
------WebKitFormBoundaryvS6HEnoxsgpmx646
Content-Disposition: form-data; name="file"; filename="test.pdf"
Content-Type: application/pdf
------WebKitFormBoundaryvS6HEnoxsgpmx646--
如何从表单数据中提取participant
和type
并将其放入可用变量中?