I have two form like this
<form action="/createFolder" method="POST" enctype="multipart/form-data">
<input type="text" name="folder" id="year" placeholder="enter year">
<input type="text" name="name" id="student" placeholder="enter your name">
<input type="submit" value="send">
</form>
<form action="/upload" method="post" enctype="multipart/form-data">
<label>File</label><br>
<input type="file" name="filedata" />
<input type="file" name="filedata" />
<input type="file" name="filedata" /><br><br>
<input type="submit" value="Send" />
</form>
in the first one user enter data and my node.js script create two folders like this "year/name"
app.post('/createFolder', upload.none(), (req, res, next) => {
const body = req.body;
if (fs.existsSync(body.folder)) {
console.log('Folder exist');
} else {
fs.mkdirSync(body.folder);
}
fs.mkdirSync(body.folder + '/' + body.name);
updateStorageConfig(body.folder, body.name);
res.redirect("/");
In the updateStorageConfig function i try to set multer.diskStorage() and then create app.post for my second form like this
function updateStorageConfig(folder, name) {
storageConfig = multer.diskStorage({
destination: (req, file, cb) => {
cb(null, folder + '/' + name);
},
filename: (req, file, cb) => {
cb(null, file.originalname)
}
});
upd = (multer({storage: storageConfig}).array("filedata", 3));
app.post("/upload", upd, function (req, res, next) {
let filedata = req.files;
if(!filedata)
res.send("Error");
else {
res.end();
}
});
If i create the fist folders its work ok, but when i create another folders, files from second form downloads in old direction.
How change the direction??
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…