1

I want to create checksum(MD5) for the large files(around 1 GB) uploaded in the blob. I an using blob trigger azure function. Any approach. currently, my code is this

    const {
    exec
   } = require('child_process');

function execShellCommand(cmd) {
    return new Promise((resolve, reject) => {
     exec(cmd, (error, stdout, stderr) => {
      if (error) {
       console.log(error);
      }
      resolve(stdout? stdout : stderr);
     });
    });
   }

module.exports = async function (context, myBlob) {
    context.log(myBlob.toString());
    context.log(context.bindingData.blobTrigger);
    const data = myBlob.toString();
    const output = await execShellCommand(`echo -n ${data} | md5sum`);
    context.log(output);
    context.bindings.outputBlob = output;
};

but this will not handle big files

gavisic
  • 59
  • 1
  • 7
  • Isn't the has already calculated for you by the time the trigger fires? `myBlob.properties.contentMd5` -- i'm not a javascript guy, but I can get it by calling `myBlob.Properties.ContentMD5` in C#/.NET – Andy Aug 11 '20 at 13:28
  • I checked that, it has null value. Do we have to enable any option for auto calculation of md5? The blob are stored in container by an adf jobs. – gavisic Aug 11 '20 at 14:43
  • There is a method that I sometimes have to call before I can use that is: `myBlob.fetchAttributes()` -- is there anything like that on that object? That will ask the server to fill in the properties object. – Andy Aug 11 '20 at 15:31
  • Thanks, @Andy I can find then in `myBlob.properties.contentMD5`. just wanted to confirm one more thing. Does azure calculate md5 for all files by default? – gavisic Aug 11 '20 at 19:09
  • I'll add an answer – Andy Aug 11 '20 at 19:25

1 Answers1

0

You don't have to calculate the MD5 yourself. By default Azure Blob Storage calculates this for you automatically.

It will be available to you via this property:

myBlob.properties.contentMD5
Andy
  • 12,859
  • 5
  • 41
  • 56