Can I use a user variable as fl_attahcment filename?
I have a PDF file in my media library that I want to download as an attachment with a filename determined by its context variable "filename".
Everything works fine if I use a static filename in fl_attachment like this:
...../fl_attachment:my-file-name/I1589983424082.pdf
However, I get an error when I am trying to do something like this:
...../$filename_ctx:!filename!/fl_attachment:$filename/I1589983424082.pdf
Is the variable expansion supported in fl_attachment at all?
-
Hi Leo,
It's not possible to use variables with the 'attachment' flag; Only some transformation options support variables, and there's a list in the documentation here: https://cloudinary.com/documentation/user_defined_variables#variable_types_and_supported_parameters
To set the attachment name based on a value stored in the asset's context, there are two possible ways to make it work:
- Use the Admin API to periodically synchronise your database with the assets' metadata, then add the filename to the URL based on that value from your database: https://cloudinary.com/documentation/admin_api#get_resources
- If it must happen in client-side code and the asset has a unique tag or is one of a small number of assets sharing a tag, load the asset's metadata in your code using a client-side resource list (which includes the context values), and use that to set the filename: https://cloudinary.com/documentation/advanced_url_delivery_options#client_side_asset_lists
If you need any examples of either method, or if there's anything else I can help with, please let me know
Regards,
Stephen
Please sign in to leave a comment.
Comments
3 comments