This should be pretty simple, but I'm having some trouble.
I want to read a jpg file from the local "assets" directory in my angular app, and calculate the hash of the image file.
I am having some trouble though accessing the actual file. By looking at various resources, I came up with this, and installed
const fs = require("fs");
const crypto = require("crypto");
const fileBuffer = fs.readFileSync(`assets/${`assetFile`}`)
const hashSum = crypto.createHash('sha256');
hashSum.update(fileBuffer);
const hex = hashSum.digest('hex');
console.log(hex);
return hex.toString();
The right now problem is fs.readFileSync doesn't work, and I'm a little confused if I can use it to "fs" to read the file. Or should I be using https or something, even though the image and the code or on the same machine?