NodeJs change name of file uploaded with formidable

0

How can I change the name of the files I upload so they do not have names like these: upload_0b4d7f947b059eff4197c048e9c0dc4e.png

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)
    })
})
    
asked by jose angel 17.12.2018 в 16:20
source

0 answers