Created
June 11, 2020 02:18
-
-
Save parzibyte/21b9ebec08ed93b3e7d0c469bb5963c4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app.post('/fotos_producto', (req, res) => { | |
const form = formidable({ | |
multiples: true, | |
uploadDir: DIRECTORIO_FOTOS, | |
}); | |
form.parse(req, async (err, fields, files) => { | |
const idProducto = fields.idProducto; | |
for (let clave in files) { | |
const file = files[clave]; | |
const nombreArchivo = file.name; | |
await productoModel.agregarFoto(idProducto, nombreArchivo) | |
} | |
}); | |
form.on("fileBegin", (name, file) => { | |
const extension = path.extname(file.name); | |
const nuevoNombre = uuidv4().concat(extension); | |
file.path = path.join(DIRECTORIO_FOTOS, nuevoNombre); | |
file.name = nuevoNombre; | |
}) | |
form.on("end", () => { | |
res.json({ | |
respuesta: true, | |
}) | |
}) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment