
const fs = require("fs");
const imageUpload = picture => {
  var timestamp = Date.now();
  var num = Math.floor(100000 + Math.random() * 900000);
  var uri = "products/" + timestamp + num + ".jpg";
  var base64Data = picture.replace(
    /^data:image\/(png|jpeg|gif|jpg);base64,/,
    ""
  );
  fs.writeFile(
    "public/images/products/" + timestamp + num +".jpg",
    base64Data,
    "base64",
    async err => {
      console.log(err);
    }
  );
  var imgs = [];
  imgs['imagePaths'] = uri;
  imgs['timestamp'] = timestamp;
  return imgs;
};
module.exports = {
  imageUpload
};
