md5 as part of output filename

Archived from the Transloadit support forum. Originally posted on August 6, 2013; details may be outdated, see our docs for current behavior. Original thread

I have enabled the "calc_md5_hash": true parameter on an encoder, but I don’t see the hash anywhere in the results…
Ideally I’d like each “output” file to be renamed to include the unique hash (so overwrites don’t matter, always the same content)

{
  "steps": {
    "videomp4": {
      "robot": "/video/encode",
      "preset": "iphone-low",
      "width": 320,
      "height": 300,
      "hint": true,
      "calc_md5_hash": true
    },
   "export": {
      "use": [
        "videomp4"
      ],
      "robot": "/cloudfiles/store",
      "container": "xxxx",
      "user": "xxxx",
      "key": "xxxx",
      "path": "${fields.dir}${file.url_basename}_${md5hash}.${file.ext}"
    }
  }
}

Hey Alan,

the md5 hash is not made available as a field variable. We can add that, I have added a todo to look into this tomorrow.

There are other assembly variables like ${unique_prefix} to prevent overwriting of files, though. See here: https://transloadit.com/docs#assembly-variables

Kind regards,
Tim

Co-Founder Transloadit
@tim_kos

Hi,

I would like to use the MD5 of the original file from the import step in the filename of my export step. I see there is `unique_original_prefix`, but it’s not clear that this is a hash of the file contents or something that changes between assemblies even if the same file is uploaded across multiple assemblies.

S

Hey Stevie,

no the unique_original_prefix is just the first two letters/digits of the original_id, which is the id of the originally uploaded file. So over time, this will not be unique.

Is this just for making sure files are always unique? Or is this about making sure the same file is not uploaded twice to your system? If it’s the former, using ${file.id} should suffice as that is a uuid. If the latter, you could match the generated md5_hash with your records in your database.

I might not see the full picture, so do you mind explaining your use case a bit? Then we can find a good solution here I am sure.

Kind regards,
Tim

Co-Founder Transloadit
@tim_kos

Hi,

This ticket has been inactive for some time so I’m closing it for now. Feel free to re-open at any time.

Kind regards,
Kevin