Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- router.post('/uploadImage', (request, response) => {
- const form = new formidable.IncomingForm()
- const address = path.dirname(__filename).split('/')
- address.pop()
- form.uploadDir = `BACKEND/imagenes/`;
- form.keepExtensions = true;
- form.maxFieldsSize = 10 * 1024 * 1024;
- form.multiples = true; //multiples archivos
- form.parse(request, (err, fields, files) => {
- if (err) {
- response.json({
- message: 'error al subir la imagen',
- data: []
- })
- }
- let data
- console.log('FILES = '+files)
- let filesPath
- if (Array.isArray(files)) { //Si se han subido mas de un archivo, es decir, si es un Array de archivos
- filesPath = files.map(file => file.path)
- } else {
- filesPath = files.path
- }
- response.json(data)
- })
- })
Add Comment
Please, Sign In to add comment