Calculating Checksum

Calculating Checksum

The file upload methods require a checksum (which is a SHA-256 hash of the file’s content) to ensure that the binary content is transferred correctly. You can use the following code sample to calculate checksum:

Code Sample

var crypto = require('crypto'); // node crypto lib used to get the sha256 checksum of the file

var hash = crypto.createHash('sha256');
var computedHash;
hash.setEncoding('hex');
        
// calculates the hash in a stream, one chunk at a time, then read the result when we're all done
hash.on('finish', function () {
    hash.end();      	
    computedHash = hash.read();
    
    //pass hash to upload method in SDK
});
        
//start the hashing process
file.pipe(hash);
            

Copyright © 2015-2017, Verizon and/or its Licensors. All rights reserved.