Write image file with nodeJS

1

I get an image in the image: date format and need to save it as an image on the server, I tried:

  var imageData = req.body.imagem.replace(/^data:image\/png;base64,/, "");

  fs.writeFile(url, imageData, 'base64', function(err) {
    if(err) res.send(err);
    new UsuarioModel().updateFoto(req.body.id, url).then(function (rows) {
      res.json(rows);
    }, function (err) {
      res.send(err);
    })
  });

This does not cause any errors, it generates the file with the correct name, however the images are blank, I already checked if the directories were allowed and if the image: date was correct and everything is right. Would anyone know how I can solve this problem?

    
asked by anonymous 28.06.2016 / 23:05

0 answers