CMS Development

Anton
Recognized Expert | Diamond Partner
Recognized Expert | Diamond Partner

Get fielsize from filemanager into module

SOLVE

Hey fellow community members, 

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.

 

Anybody an idea?

 

 

best, 

Anton

Anton Bujanowski Signature
0 Upvotes
1 Accepted solution
stefen
Solution
Key Advisor | Partner
Key Advisor | Partner

Get fielsize from filemanager into module

SOLVE

@Anton You can find that by using the file_by_id HubL function like so:

{% 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.

Stefen Phelps, Community Champion, Kelp Web Developer

View solution in original post

2 Replies 2
stefen
Solution
Key Advisor | Partner
Key Advisor | Partner

Get fielsize from filemanager into module

SOLVE

@Anton You can find that by using the file_by_id HubL function like so:

{% 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.

Stefen Phelps, Community Champion, Kelp Web Developer
Anton
Recognized Expert | Diamond Partner
Recognized Expert | Diamond Partner

Get fielsize from filemanager into module

SOLVE

Man, I feel kinda dumb right now 😀

Thank you very much. Works flawlessly with HubDB

 

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

 

best, 

Anton

 

Anton Bujanowski Signature