如何改变文件名,当使用express-fileUpload?



如何更改上传至服务器的文件的文件名?

app.post(URL, (req, res) => {
let fileName = req.files.file.name;
req.fileUpload;
res.statusCode = HTTP_OK;
res.send("Good Job")  })

我在uplodFile:

中得到了这个设置
app.use(
fileUpload({
createParentPath: true,
useTempFiles : true,
tempFileDir : "path",
})

);

代码将文件保存在正确的目录中,但名称类似于"tmp-2-1654614752945"

有人能帮帮忙吗?

谢谢。:)

app.post(URL, (req, res) => {
if (!req.files) {
return res.status(400).send("No files were uploaded.");
}
const file = req.files.file;
const fileName = file.name
const path ="path" + fileName;
file.mv(path, (err) => {
if (err) {
return res.status(500).send(err);
}
testSelection.files = fileName;
return res.send({ status: "success", path: path });
});

});

最新更新