La idea subir archivos a un servidor express manteniendo el nombre original.
Formulario HTML
<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>
Server
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 <===
Al subir un archivo file.txt se obtiene: No files were uploaded.