Issue with downloading documents from database

I’m having trouble using the wixData.get() function to download a document from my site’s database. Has anyone else used the function this way?

This is my code:

import wixData from ‘wix-data’;
export function downloadGuidelines_click(event, $w) {
wixData.get(“guidelines-documents”, “1”);
}

I used it a few weeks ago and it successfully downloaded the file in the first line of my database. Now it does not work.

Suggestions for other ways to download files stored on the site would also be appreciated :slight_smile:

Thanks!

The second parameter in get() is the item’s ID , not the position. Also, get() returns a promise. So, you need something like this:

wixData.get("guidelines-documents", <item ID>)
.then( (results) => {
    let doc = results.doc;
    wixLocation.to(doc);
} )
.catch( (err) => {
    let errorMsg = err;
} );

See the wixData.get() API for details.

Thanks Yisrael! This works :slight_smile:

1 Like