Using Transloadit's "notify_url" to Manipulate Assembly Results JSON
The Transloadit Assembly results JSON has all kinds of information about the processed files, but we need this information to appear in our business database. We need to use some practical scripting to massage the results JSON, and get it loaded into our db how we like.
Use "notify_url" to send to a webhook, which runs a script
Transloadit template can be set to send its json results payload to a
notify_url which could be a url you set up at a web service like Hookdoo or others.
Hookdoo's webhook can run a shell script like
transloadit-hook.sh below, on one of your servers. The payload can be parsed there, and some action can be taken. In our case, this script:
- is triggered only if a rule set in the Hookdoo webhook is true, which is determined by the url param
?whatever=12345abcde. This can be anything you like.
- gets a couple of variables sent to it by Hookdoo, but these could also be set up as environment variables on the target server.
- sets up a bunch of environment variables for safety's sake, because depending upon how the script is run by Hookdoo on our server, it's possible that some of those binaries are inaccessible.
- massages the Transloadit payload by using php to decode, splitting into signature and transloadit parts with awk, getting a local hmac signature via openssl, for later comparison to the received signature. Continues on, using jq to extract some parameters like
template_idfrom the payload json, and also to re-arrange the json into something our database will accept.
- next it uses
ifstatement, to check if the locally-calculated signature matches the one that came with the payload. If it does, then it loads the massaged json (the
tassy-db-ready.json) up to the db.
In the end, users can drag some images to Uppy, which in turn uses Transloadit to quickly process the files, send the payload to a webhook, which runs a script, checks the signature, and uploads to a database within a few seconds.
Now our users can easily reference and search what they uploaded.