Check if file exists from app structure

Good day everybody!
Is it possible to check from the app structure if a specific file exists?
I have the following scenario:
A table where every row has download links to one mp3 and one zip. I want the buttons only to show, when this files actually exists on the server. I simplified the files already by naming them with the id of each database entry (Like 2319.mp3 and 2319.zip). The advantage of this is, I don’t need to store the file path in the database since I can get the ID from the table body, the directory is always the same. So the link is /dir/{{ID}}.mp3. That works perfectly.

I already tried a serverconnect which is linked to a server action with a file exists. But dynamic attributes (in this case “show”) can’t load server connects with input parameters.
If there is a way to check files on table load, would it increase load time?

you can use server action “Add If File Exists”

Yeah I’m experimenting with that since a few hours. I already have put the serverconnect in the table repeat which then loads “if file exists” with the row ID. The problem is, I cannot select any dynamic parameters in the server connect. It justs resets after I blur the Input parameter. I guess I have to report this as bug

yeap it is bug in V1.5.1. I know but it is not server side … this bug in client side (app connect). @George or @Teodor can check this error.

can you share your server side and client side (screen shot)

1 Like

Yeah it’s definitely client side! If this works, I guess I already have figured it out. I have a paged table so it loads only 20 records. So I guess it’s no problem to check each download button with the server side “if file exists”.
Another option would be to crawl through the entire database and check each file link and check a Boolean in a column if the file exists. This way, there would be no heavy load on the client side and the table could be retrieved instantly. But it’s more complicated and then there is the question when to do the crawling. The table is very dynamic and it reloads whenever a record changes so I’d rather do this on the client side and with each table page.

yeap this is right idea …
just a suggestion : you can use cron job and you can run your script hourly/ daily etc…

1 Like

Thank you for this hint I have this gut feeling that I’m gonna need cron jobs later in this project. For now, I’m gonna check out how the performance is with the client side solution. Would be great if it works since no real chain has to be set when a file gets uploaded or deleted. The client detects the change as soon as the table loads

Ok I got it. Placed a serverconnect inside the cell which is linked to a server action that checks “if file exists: /dir/{{$GET_ID}}.mp3”. The filecheck has output enabled and I can use this Boolean to show or hide the download button. Performance seems to be the same as without the check.
Thank you for your time!

3 Likes

you are welcome @jowhiskey

1 Like