I'm building a module for our ressources page an would like to display the filesize of each file which is uploaded to the filemanager in a module which gets all the other information from a HubDB. The current workaround is a textfield where the colleague who will manage the HubDB can input a number and then it is displayed with the |filesize and a multiplier filter in the module. But since this isn't very convinient convinient my idea was to automate this step.
{% set file = file_by_id(123) %}
{{ file.size }}
<!-- this will print the size in bytes -->
However, the issue I've run into with this is that it's not very easy to get a file ID to use with this function since it's not really a user facing ID or a field available in custom modules. If you find a way to surface this ID easily I'd love to know.
{% set file = file_by_id(123) %}
{{ file.size }}
<!-- this will print the size in bytes -->
However, the issue I've run into with this is that it's not very easy to get a file ID to use with this function since it's not really a user facing ID or a field available in custom modules. If you find a way to surface this ID easily I'd love to know.
Yeah, you're right... It's a bummer that if you use the "image" function in a custom module you only get the url and the sizes... If I come up with something I will keep you in touch.
Maybe with the new files API(when it's gonna be availibe) you will be able to get the ID by file url