我正在使用以下内容通过Multer将文件上传到目录。效果很好,但是上传后我需要执行一些操作,这些操作需要我刚刚发布到“upload”目录中的文件名。如何获得刚发布的文件的名称?

// Multer storage options
var storage = multer.diskStorage({
  destination: function(req, file, cb) {
    cb(null, 'upload/');
  },
  filename: function(req, file, cb) {
    cb(null, file.originalname + '-' + Date.now() + '.pdf');
  }
});

var upload = multer({ storage: storage });

app.post('/multer', upload.single('file'), function(req, res) {
  // Need full filename created here
});

最佳答案

var express=require("express");
var app=express();
var multer=require("multer");
var upload=multer({dest:"uploads/"});
app.post("/multer", upload.single("file"), function(req,res){
    console.log(req.file.filename);
});

关于node.js - Node/Multer 获取文件名,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/34328846/

10-12 15:09