-2
I am performing an operation where basically the client will be sending the images you want to the server. This way the way I am putting to occur the rescue is correct, but the user will not be saving the photos only in one place. These photos have to be saved in several directories, by choosing the user. Ex: I have students and these students have a folder for each, so this folder stores several photos and information, if I go on a student’s profile and upload a photo of it, this photo has to be saved in your directory.
And with that came the problem. I’m using Multer to perform this upload and nodejs operation.
Multer:
var multer = require('multer')
var storage = multer.diskStorage({
destination: function (req, file, cb) {
let caminhoFoto = './public/lib/face-api/labels/Karen/'
cb(null, caminhoFoto)
},
filename: function (req, file, cb) {
cb(null, file.originalname)
}
})
var upload = multer({ storage })
router.post('/uploadFacial', upload.single('uploaded_file'), function (req, res) {
console.log(req.file, req.body)
res.redirect('back')
});
Front:
<form action="/alunos/uploadFacial" enctype="multipart/form-data" method="post">
<div class="form-group">
<input type="file" class="form-control-file d-inline" name="uploaded_file">
<input type="text" value="{{aluno._id}}" class="form-control-file d-inline" name="aluno">
<input type="submit" value="Enviar foto" class="btn btn-default">
</div>
</form>
I was wondering if in any way it is possible to change this location that is saved the upload according to the information received from the front or if there would be some other way to be doing this operation?