Thursday, 11 May 2017

Best way to get data android NodeJS

I am building a android application with android studio using nodejs on server side, and i am a little confused about this: req.params,req.query,req.body

I am not confused about what they do, i know how they work, i am just confused on what should i use and when.

For example i have a example where i want to upload a photo to the server and that foto should be related to a specific group, so i need to send the group in this case of plants and save the image inside that folder, so i need to send the image (i use base64) and the group of plants related to that image, here is a example:

app.post('/fotos/:flourName', function (req, res) {
    //send image in body already decoded
    var bitmap = new Buffer(req.body.image, 'base64');
    fsPath.writeFile("images/" + req.params.flourName + "/example2.png", bitmap, function (err) {
        if (err) {
            return err;
        }
        res.json({ statusCode: 200 });

    });
})

i am using req.params.floourName in this case, but i could use req.query or send that in the body, any example of how to concern about this?



via Antonio Costa

No comments:

Post a Comment