I'm using react-dropzone
, I would need a way to be able to calculate the sha256
of the file when the file is selected then inside the onDrop()
function, to use it as a checksum for the checks I'm doing.
I thought of using CryptoJS
, but it doesn't return to me what I hope it should return to me, that is, a 64-character code.
function Dropzone(props) {
const { acceptedFiles, getRootProps, getInputProps } = useDropzone({
onDrop: props.onDrop
});
const file = acceptedFiles[0];
return (
<div>
<Typography>File Name</Typography>
{file ? (
<p>
{file.path} - {file.size} bytes
</p>
) : (
<p />
)}
<div {...getRootProps({ className: 'drop-zone' })}>
<input {...getInputProps()} multiple={false} />
<p>Drag 'n' drop files here, or click to select files</p>
</div>
</div>
);
}
const onDrop = files => {
console.log(files);
};
<Dropzone onDrop={onDrop} multiple={false} />