(SOLVED using StaticWix) Download FILE from collection when button clicked

Hello everyone, first of all I would like to take this opportunity to thank everyone here in this community for sharing code reference and ideas. So I started using WixCode 13 days ago, everything is blank . But thanks to this community I was guided. I am so happy for what I achieved today. From scratch I have created my 1st Admin dashboard using WixCode , with site members using App members connected to my own made site_member_database to which i can control its information data. The numbers shown on my dashboard are all connected to my database. Thank you once again.

Okay let’s go back to my question, I have a page where only ADMINS are allowed to enter, then the Admin can attached a FILE saved to “materials_db” collection.

On the other pages, only site members are able to enter and download the file then DATA Info of the user who downloads it will be saved to my “downloads” database, I already manage to do that.

Example pages:
Page Title 1
- File 1
Page Title 2
- File 2

Now on the code with red box, it will search the materials name based on the page title text so the site member can able to download the RIGHT file on the page where she/he on to.

I don’t want to attached a file on “BUTTON”, I want a user to download on the Collection where my files are being attached by the admin.

I read some of the post about wix.location then the ID but i got “Forbidden” display.

Thank you. :slight_smile:

For starters, is that your actual file URL that you can simply get from your media manager and then clicking on the needed file that you want.

The next thing to check would be the actual permissions for the dataset that you are storing the downloadable files in or the page where the files are shown on.
https://support.wix.com/en/article/troubleshooting-dynamic-pages-issues#cant-access-dynamic-pages-1

Plus, for downloading things, you don’t always have to use a button…
https://support.wix.com/en/article/adding-a-download-button

…to let the user download and you can still do it without the use of code.
https://support.wix.com/en/article/working-with-the-connect-upload-button-panel
https://www.wix.com/corvid/forum/corvid-tips-and-updates/create-a-download-button-for-uploaded-documents

If you are wanting to do something through code, you can always look at doing something like this from Nayeli (Code Queen) if you want to setup a downloadable repeater display for example.

Corvid Tutorial to download a document and hide WixStatic URL
https://codequeen.wixsite.com/document-download

Trigger Auto Download for Image on Wix while hiding wixstatic.com
https://codequeen.wixsite.com/auto-download

@givemeawhisky Thank you sir,. I was thinking about making a dynamic page base on my uploaded data on my materials DB, but I still need to understand more how dynamic pages work, coz im not sure if the page automatically populate base on data collection, since you can set your dynamic url base on one of your DB fields. And I still don’t know how to access dynamic pages. =x

Thank you for this
Corvid Tutorial to download a document and hide WixStatic URL
https://codequeen.wixsite.com/document-download
I never saw this on search result, I only found the trigger auto video…

Im sorry but the video is private and i wish not to use a repeater.

I can easily link or attached document to a button using dataset but i dont want that because I need to have a record of my files on a database, that is why I have an upload file page.
Media files are VISITORS UPLOADS from an admin Webpage.

I tried this code when a user click the button download.

export function buttonPDF_click(event) {

wixData.query(“materials_db”)
.eq (“title”, “reg7”) //Find the file title which is “reg7”
.find()
.then((results) => {
let documents = results.items;

 wixLocation.to(documents[0].pdf) 

}

This link gives me forbidden display
wixLocation.to(https://docs.wixstatic.com/ugd/$48434559-8a5a-4a16-bbdf-30e977f70798?dn=$reg7.pdf);

Other thing is only the login site members are able to download, when they logout they are not able to download the file when they copy or re click the download link from Browser download history.
ex. chrome://downloads/

Hello @givemeawhisky I did try using Dynamic pages, it is good since it can download the file exact file of the exact location…
Ex.
Page 1
- File 1
Page 2
- File 2
This is the exact URL
https://42838223-8b75-4f09-ba96-c12e26a9d0d1.filesusr.com/ugd/35f018_37825c1e48d147a99931730649bc0d1c.pdf

However when i try to add a click event on download button, the file download will not going to function. Because I have a code that collects info when a user click the download button.