Image upload with problem in nodejs

0

I'm running a test to implement an image upload and I've created the following code on the backend on node js.

function uploadImagem (req, res) {
    var restauranteId = req.params.id;
    var file_name = 'No subido...';

    if(req.files){
        var file_path = req.files.image.path;
        var file_split = file_path.split('\');
        var file_name = file_split[2];

        res.status(200).send({
            file_path: file_path,
            file_split: file_split,
            file_name: file_name
        });
    }else{
        res.status(200).send({message: 'não a solicitação de usuário'});
    }


}

When I submit the data it only falls into the condition below;

    else{
            res.status(200).send({message: 'não a solicitação de usuário'});
        }

I'm doing so;

Theexpectedresultwastolooklikethis;

How do you get around this?

By doing the suggestion of @Thiago Magalhães the method was thus;

function uploadImagem (req, res) {
    res.status(200).send({message: req.body.fles});
    var restauranteId = req.params.id;
    var file_name = 'No subido...';

    if(req.files){
        var file_path = req.files.image.path;
        var file_split = file_path.split('\');
        var file_name = file_split[2];

        res.status(200).send({
            file_path: file_path,
            file_split: file_split,
            file_name: file_name
        });
    }else{
        res.status(200).send({message: 'não a solicitação de usuário'});
    }


}

I can not use console.log() because it's a test done in the backend, so I used res.status(200).send({message: req.body.fles}); , I also tested with res.status(200).send({message: req.body.image}); However the two results give% empty%.

    
asked by anonymous 08.08.2018 / 21:19

0 answers