Hello, I am trying to get the HASH value of a file. The fact, is that I want, before a user uploads a file, to check that that file has not been previously uploaded.
I have looked in ARAS and the system already saves that value in "checksum" itemtype "file", but it does not do any checking. This entire process is done in the file "xxhash-asm.min.js", which is in innovator\client\vendors.
But the line where it calculates it (line2) is not tabulated and has 132,387 characters, and I am not clear. I have tried other methods, to make myself a method, but it fails on this line: "crypto.subtle.digest('SHA-256' , data).then(function (hashBuffer) {"
Any suggestions, I suppose there must be an easier way to calculate/extract the HASH of a file.
My method:
var innovator = new Innovator(); aras.vault.selectFile().then(function (fileObject) { file = fileObject; var reader = new FileReader(); reader.readAsText(file); // Aquí calculamos el hash del contenido del archivo reader.onload = function (readerEvent) { var content = readerEvent.target.result; // Este es el contenido del archivo // Calcular el hash del contenido del archivo calcularHashDeContenido(content, function (hash) { alert('Hash del archivo:', hash); }); }; }); // Función para calcular el hash de un contenido function calcularHashDeContenido(content, callback) { const crypto = window.crypto || window.msCrypto; // Obtener la implementación de crypto const encoder = new TextEncoder(); const data = encoder.encode(content); alert(1); crypto.subtle.digest('SHA-256', data).then(function (hashBuffer) { alert(2); const hashArray = Array.from(new Uint8Array(hashBuffer)); const hashHex = hashArray.map(byte => byte.toString(16).padStart(2, '0')).join(''); callback(hashHex); }); }
I see in js files in ARAS Directory, that exist "getFileChecksum(fileName);", but I can't get it to work.
This is in "\Aras\Innovator\Innovator\Client\javascript\Aras\Client\Controls\Public" file Vault.js