const express = require('express');
const router = express.Router();
const multer = require('multer');
var csv = require("fast-csv");
var fs = require('fs');
const Contact = require('../models/contacts');
var DIR = './uploads/';
var upload = multer({ dest: DIR }).single('file');
//uploading a csv
router.post('/uploads', function (req, res, next) {
var path = '';
upload(req, res, function (err) {
if (err) {
// An error occurred when uploading
console.log(err);
return res.status(422).send("an Error occured")
}
// No error occured.
path = req.file.path;
return res.send("Upload Completed for " + path);
});
})
我想使用MEAN Stack导入动态CSV文件。使用Angular上传文件,并将其上传到uploads文件夹中,我不想硬引用数据类型,因为我想上传随机CSV并将其用于进一步的目的。我看到的所有示例都基于预先定义的CSV(EX:名字,等级编号等),这不应该是我的情况。请帮助
这是我的Route.js,文件上传到Uploads文件夹,现在如何进一步解析,如何在mongo中动态编写模式