How to download files from Dynamic Database

Okay final update, hopefully. I got it to work! The code in the original post was actually good except for the wixLocation. I went to Nayeli’s (Code Queen) website she had linked in one of her videos, and decided to copy the code she had there. One of the biggest things that I’m questioning is the ${url} and ${filename}. In her code that I did a copied and pasted had those parts look like normal black lines of code and not pink. Every time I typed it out myself, that part would always be pink. Anyway, that updated part caused the Forbidden screen to appear, but the url changed. It showed the actual file it was trying to access. I managed to make it work by remove everything in the .to() part except the ${filename}. The file downloaded and showed the Light Box.

For anybody who comes across this post, this is what my code looks like (altered for general naming). Make sure to change everything that is unique to your naming scheme such as button, item. file, the let names (can be whatever you want), and $w("# dynamicDataset). You may not need the item. note. It depends on your Dataset. I hope it helps for others :

import wixWindow from 'wix-window';
import wixData from 'wix-data';
import wixLocation from 'wix-location';
let source;
 
$w.onReady(() => {

$w('#button1').onClick(() => {

     $w("#dynamicDataset").onReady( () => {
 //assign the hasDoc variable the value of the field that holds the document in the current item of the dataset.
 
 let item = $w('#dynamicDataset').getCurrentItem();
 let soundPack = item.note;
 let url = soundPack.split("/")[3];
 let filename = item.file;
    wixLocation.to(`${filename}`);

    $w('#button1').disable()
    $w ('#button1').label = "Downloaded"
    wixWindow.openLightbox('TFD') 
 
 });

})

})

1 Like