Templates
This guide assumes that you are familiar with building assembly instructions.
Basics
Templates are a way to securely store assembly instructions on our servers. You could also pass them directly in the hidden params parameter on your form.
However, it is important to know that the preferred method of integrating Transloadit is via templates. While it is convenient to specify your assembly instructions directly in the
params field of your form, that approach has two major problems:
- Visitors of your site can see the assembly settings you are using when checking your HTML source code.
- Embedded secrets such as S3/SFTP access credentials are visible!
You should only consider not using a template when your assembly instructions are dynamic and you are not exposing access credentials in your template. Our /http/import robot is a good example of when you will likely use the params parameter instead of a template.
Creating a template is easy. You create a template on the Transloadit website with your account. All templates are encrypted using 256 bit AES encryption and securely stored on our servers.
Creating a template
- Login to your account.
- Click on the "Templates" link under "My Account", then click "Create template".
- Give your template a description. This is just for you as a reference.
- Provide the JSON for your template.
- Hit the save button.
You should now see a page showing the template you entered. On top of the page
you will find your template_id which looks like this:
"4b62ee4dbb38455d96fe13d972ec3211". This id is all you need to use the
template.
Hint: For your convenience, there also is a "Test it!" section where you can upload a file and see if your template does what you expect it to do.
Using a template
Given an existing template_id, using it is as simple as replacing your
assembly steps with the template id. For example:
{
"auth":{"key": "YOUR-API-KEY"},
"steps": {
"encode":{
"robot": "/video/encode",
"preset": "iphone"
},
"export":{
"robot": "/s3/store",
"key": "your-key",
"secret": "your-secret",
"bucket": "your-bucket"
}
}
}
Would become:
{
"auth": {"key": "YOUR-API-KEY"},
"template_id": "4b62ee4dbb38455d96fe13d972ec3211"
}
Passing variables into a template
In addtion to a template_id, you can also specify other parameters. These can
act as variables that will be recursively merged into your template.
Considering our previous example:
{
"auth":{"key": "YOUR-API-KEY"},
"steps":{
"encode":{
"robot": "/video/encode",
"preset": "iphone"
},
"export":{
"robot": "/s3/store",
"key": "your-key",
"secret": "your-secret",
"bucket": "your-bucket"
}
}
}
You could merge additional logic into the template like this:
{
"auth":{"key": "YOUR-API-KEY"},
"template_id": "4b62ee4dbb38455d96fe13d972ec3211",
"steps":{
"export":{
"bucket": "other-bucket"
}
}
}
Which is merged to create the following assembly:
{
"auth":{"key": "YOUR-KEY"},
"steps":{
"encode":{
"robot": "/video/encode",
"preset": "iphone"
},
"export":{
"robot": "/s3/store",
"key": "your-key",
"secret": "your-secret",
"bucket": "other-bucket"
}
}
}
These additional params would be passed to your form using the hidden "params" field. Check the minimal integration again to see how this is done.