如何在 transloadit 汇编指令中访问 rails 表单字段值
How to access rails form fields value in transloadit assembly instructions
我正在使用 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 重命名文件。查看说明的相关摘录,
"export": {
"use": [
"base",
"large",
"medium",
"thumb"
],
"robot": "/s3/store",
"key": "********",
"secret": "********",
"bucket": "********",
"path": "${unique_original_prefix}/${previous_step.name}/${fields.coach[name]}.${file.ext}"
}
但是这不起作用。结果文件是,
5e
/f88480973a11e49ecf65da10504cf1
/base
/.jpg
/large
/.jpg
/medium
/.jpg
/thumb
/.jpg
我做错了什么?
奖金:
还有一种方法可以使用 transloadit 对字段值进行参数化,或者我应该只设置一个隐藏的输入字段,在提交表单时将其设置为正确的值。我想这也可以让我规避第一个问题,但不知何故感觉很脏。
您正在使用 ${unique_original_prefix},其工作方式如下:
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.
然后 ${unique_prefix}:
A unique 33-character prefix used to avoid file name collisions, such as “f2/d3eeeb67479f11f8b091b04f6181ad”
请注意这两个程序集变量将如何创建一个双字符子目录,您会在结果中看到它。路径的其余部分是预期的。
如果您想要没有双字符子文件夹的唯一前缀,请使用 ${assembly.id} 而不是 ${unique_original_prefix}。
关于奖金,你可以在你的汇编参数中添加一个 "fields" 对象(就像你添加 "auth" 和 "steps" 一样)。这些也将作为字段提供。例如,您可以通过在该对象中发送它然后将其用作 ${fields.my_custom_unique_prefix} 来添加您自己的唯一前缀。只需确保使用 "my_custom_unique_prefix" 作为字段对象中的键即可。
亲切的问候,
蒂姆
联合创始人 Transloadit
@tim_kos
我正在使用 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 重命名文件。查看说明的相关摘录,
"export": {
"use": [
"base",
"large",
"medium",
"thumb"
],
"robot": "/s3/store",
"key": "********",
"secret": "********",
"bucket": "********",
"path": "${unique_original_prefix}/${previous_step.name}/${fields.coach[name]}.${file.ext}"
}
但是这不起作用。结果文件是,
5e
/f88480973a11e49ecf65da10504cf1
/base
/.jpg
/large
/.jpg
/medium
/.jpg
/thumb
/.jpg
我做错了什么?
奖金: 还有一种方法可以使用 transloadit 对字段值进行参数化,或者我应该只设置一个隐藏的输入字段,在提交表单时将其设置为正确的值。我想这也可以让我规避第一个问题,但不知何故感觉很脏。
您正在使用 ${unique_original_prefix},其工作方式如下:
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.
然后 ${unique_prefix}:
A unique 33-character prefix used to avoid file name collisions, such as “f2/d3eeeb67479f11f8b091b04f6181ad”
请注意这两个程序集变量将如何创建一个双字符子目录,您会在结果中看到它。路径的其余部分是预期的。
如果您想要没有双字符子文件夹的唯一前缀,请使用 ${assembly.id} 而不是 ${unique_original_prefix}。
关于奖金,你可以在你的汇编参数中添加一个 "fields" 对象(就像你添加 "auth" 和 "steps" 一样)。这些也将作为字段提供。例如,您可以通过在该对象中发送它然后将其用作 ${fields.my_custom_unique_prefix} 来添加您自己的唯一前缀。只需确保使用 "my_custom_unique_prefix" 作为字段对象中的键即可。
亲切的问候, 蒂姆
联合创始人 Transloadit @tim_kos