I am using transloadit to process image uploads with rails. I have included all the fields (fields: "*"
) so they are submitted with the params. I would now like to use them in the assembly instructions to rename the files. See the relevant excerpt of the instructions,
"export": {
"use": [
"base",
"large",
"medium",
"thumb"
],
"robot": "/s3/store",
"key": "********",
"secret": "********",
"bucket": "********",
"path": "${unique_original_prefix}/${previous_step.name}/${fields.coach[name]}.${file.ext}"
}
However this does not work. The resulting files are,
5e
/f88480973a11e49ecf65da10504cf1
/base
/.jpg
/large
/.jpg
/medium
/.jpg
/thumb
/.jpg
What am I doing wrong?
Bonus: Also is there a way to parameterize the field values with transloadit or should I just have a hidden input field which gets set with the proper value when the form is submitted. This I guess would also allow me to circumvent the first problem but somehow that feels dirty.
you are using ${unique_original_prefix}, which works like:
This is like ${unique_prefix} with the exception that two files that are encoding results of the same uploaded file (the original file) will have the same prefix value here.
And then for ${unique_prefix}:
A unique 33-character prefix used to avoid file name collisions, such as “f2/d3eeeb67479f11f8b091b04f6181ad”
Please notice how both these assembly variables will create a two char subdirectory, which you are seeing in your results. And the rest of the path is expected.
If you'd like a unique prefix without the two-char subfolders, please use ${assembly.id} instead of ${unique_original_prefix}.
About the bonus, you can just add a "fields" object in your assembly params (just like you are adding "auth" and "steps"). Those will also be available as fields. You could for example add your own unique prefix by sending it in that object and then using it as ${fields.my_custom_unique_prefix}. Just make sure you use "my_custom_unique_prefix" as the key in your fields object.
Kind regards, Tim
Co-Founder Transloadit @tim_kos