Download a file from file storage as authenticated user - codeless

Hello,

I am trying to build a codeless logic to download a file. The file has restricted permissions and can only be read by Authenticated users.

grafik

I tried several combinations - how can I create a link, which is only working if the user is logged in?

I also tried to create an API-Service for the download - same result - no working.

Thanks for help,
Ben

Hi Ben,

What do you need to do with the downloaded file? The codeless logic you shared sends a request to grab the file but doesn’t do anything with the file. Is the intent to let the user save the file locally?

Regards,
Mark

Hello Mark,

the user should be able to download the file (alternatively view the pdf file). But I want to restrict the access only to Authenticated users…

I also tried the “read file” block - didn’t work as well.

Best regards,
Ben

Hello @Benjamin,

The HTTP/s does not initiate a download automatically. To start the download, you need to open the URL in a browser. Try the following logic:

Please note that checking for the current user does not prevent non-logged-in users from trying to open the file directly via the URL. However, you already have permissions set up to deny access to this file for all users except authenticated ones. This check is only needed to show a message to the user instead of opening the file in a new tab with a message that is not user-friendly.

Regards,
Stanislaw

Hello all,

I don’t get it running…

grafik

The permissions for the file to access:

I built the code 1:1 from your screenshot:

What am I doing wrong?

If it helps, here the data for recreate the issue:

https://civillinen-eu.backendless.app/

Login: a@b.com
Password: 1

Thank you!
Regards,
Ben

Hi Ben,

When the URL is fetched, the request has no information about the currently logged in user. To change that behavior, you can turn on Cookie-Based Authorization:
https://backendless.com/docs/rest/users_cookie_based_authorization.html

IMPORTANT: When you use the login API, make sure the API request is sent to the same subdomain/domain from which you fetch the file. You can control that on the SETTINGS tab in UI Builder:

Regards,
Mark

Now it’s working!

Problem was the API-Domain Setting.

Thank you very much for your help!

Regards,
Ben