我有将图像上传到 S3 的表单,它运行良好。但是,对于success_action_redirect
密钥,我想要一个使用表单中的模板变量的 URL,即
{"success_action_redirect": "localhost/account/{{account.id}}"},
我似乎无法在我的帖子政策中使用它。有办法解决吗?
编辑:
这是表格中的相关行:
<input type="hidden" name="success_action_redirect" value="http://localhost:8000/account/{{account.id}}">
我假设它不起作用,因为 {{account.id}} 返回一个数字,所以当 S3 尝试将它与签名进行比较时,它正在http://localhost:8000/accounts/2
与http://localhost:8000/accounts/{{account.id}}"
.
它返回一个错误:
Invalid according to Policy: Policy Condition failed: ["eq", "$success_action_redirect", "http://localhost:8000/account/{{account.id}}"]
此外,我尝试使用{% templatetag %}
来停止{{account.id}}
成为一个变量,虽然它通过了 S3,但它(显然)没有重定向到正确的页面。
在您的策略中,您必须使用starts-with
并且$eq
不允许您的成功操作重定向 URL 匹配前缀。
因此,您的政策可能如下所示:
["starts-with", "$success_action_redirect", "localhost/account/"],
请参阅政策文档:
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句