The idea is to upload files to an express server keeping the original name.
HTML form
<form action="/procesar" method="post">
<div class="form-group">
<label for="exampleFormControlFile1">Cargar archivo nuevo</label>
<input type="file" class="form-control-file" id="FormControlFile1" name="FormControlFile1">
</div>
<div class="form-group">
<button type="submit" class="btn btn-primary mb-2">Procesar</button>
<button type="button" class="btn btn-danger mb-2" id="uno">Eliminar</button>
</div>
</form>
servers
router.post('/procesar', (req, res) => {
if (!req.files || Object.keys(req.files).length === 0) {
return res.status(400).send('No files were uploaded.');
}
// The name of the input field is used to retrieve the uploaded file
let FormControlFile1= req.files.FormControlFile1;
// Use the mv() method to place the file somewhere on your server
FormControlFile1.mv('/temp/file.txt', function (err) {
if (err)
return res.status(500).send(err);
res.send('File uploaded!');
});
});
===> express-fileupload Examples <===
When uploading a file.txt you get: No files were uploaded .
Files can only be sent in a form whose type is
"multipart/form-data"
Try this: