【发布时间】:2015-01-25 20:30:21
【问题描述】:
我是 node 和 mongoDB 的新手。我正在使用 nodeJS、express 和 mongoDB 开发一个应用程序。我想从文件输入字段中读取 csv/xlsx 文件并使用 mongoose 将其存储在 mongoDB 中。我有困难。我在前端使用 angularjs。谁能给我建议我应该通过什么程序?具体代码会很有帮助。
我使用 busboy 模块将文件存储在特定文件夹中。这是我的代码
在路线中:
router.post('/fileupload', function (req, res) {
var fstream;
req.pipe(req.busboy);
console.log(req.pipe);
console.log(req.busboy);
req.busboy.on('file', function (fieldname, file, filename) {
console.log("Uploading: " + filename);
fstream = fs.createWriteStream('./files/' + filename);
file.pipe(fstream);
fstream.on('close', function () {
res.redirect('back');
});
});
});
和我的前端:
<form method="post" action="/fileupload" enctype="multipart/form-data">
<input type="file" id="file" name="file">
<button type="submit">Submit</button>
</form>
到目前为止,没有错误。现在我只想将这些文件存储在数据库中。 接下来我该怎么做?
【问题讨论】:
标签: node.js mongodb file csv express