const express = require("express");
var fs = require("fs");
var formidable = require("formidable");
//调用路由模块
const router = express.Router();
router
.post('/', (req, res) => {
var form = new formidable.IncomingForm();
form.parse(req, function(err, fieldes, files) {
console.log(err);
console.log("---------------------");
console.log("---------------------");
console.log(fieldes);
console.log("---------------------");
console.log("---------------------");
console.log(files);
console.log(files.imgurl._writeStream.path, files.imgurl.originalFilename, "文件路径")
//读取文件
var readStream = fs.createReadStream(files.imgurl.filepath);
// 写入文件
var writeStream = fs.createWriteStream("./img/" + files.imgurl.originalFilename);
readStream.pipe(writeStream);
readStream.on('end', function() {
fs.unlinkSync(files.imgurl.filepath);
});
})
})
module.exports = router;
NodeJs上传文件
最新推荐文章于 2024-07-13 00:09:19 发布