Introducing the /file/hash Robot for file integrity
It's time again to welcome a new Robot to the Transloadit family. Say hello to the /file/hash Robot. With its introduction, it's now possible to hash any file that's part of your Assembly execution process, proving particularly useful in verifying the integrity of your file.
There are several algorithms at your fingertips to choose from too, whether you're looking to use the speedy MD5 algorithm, or a more secure option, such as SHA-512.
After the Robot is finished hashing your file, it'll store the file's hash under the
file.meta.hash
property, for you to access in later Steps.
File hashing in action
As an example, let's take a look at what a Template could look like if we wanted to verify a file has changed after it has been resized. We'll first take our uploaded file and hash it. Then, resize the original file and hash it again. Simply compare the hash from the resized image to the original hashed image. If they're different, then we know that our file has been resized.
Here's what that looks like:
{
"steps": {
":original": {
"robot": "/upload/handle"
},
"resize_image": {
"use": ":original",
"robot": "/image/resize",
"height": 500,
"imagemagick_stack": "v3.0.1",
"resize_strategy": "fit"
},
"hash_original": {
"use": ":original",
"robot": "/file/hash",
"result": true,
"algorithm": "sha1"
},
"hash_resized": {
"use": "resize_image",
"robot": "/file/hash",
"result": true,
"algorithm": "sha1"
}
}
}
Notice how we're using the sha1
algorithm? You can easily change the algorithm
parameter to any
of these options below to generate hashes with different algorithms for different use-cases.
b2
md5
sha1
sha224
sha256
sha384
sha512
Testing
Now, let's put our Template through its paces. Upload an image and take a look at the hash that is generated for the file, and if it changes throughout our Steps.
Step: hash_files |
Step: resize_image |
|
---|---|---|
meta.hash:924eb08378f97f1fe2744b77a79373078af3487c
|
meta.hash:c51c917811c2b3a515c303b682c610224aa77621
|
As expected, the hashes generated for both of our files are different, meaning our image was resized.
Until next time
That's the end of our whistle-stop tour of the /file/hash Robot. Sign up below with Transloadit and have a play around yourself with the Robot, as well as our array of other Robots.