Please I am trying to write a code to download a file through a save window the file is kept in a database sample collection
PAGE CODE
import wixlocation from ‘wix-location’;
import myGetDownloadUrl from ‘backend/media’;
export function button1_click(event) {
myGetDownloadUrl
.then((myFileDownloadUrl) => {
wixlocation.to(myFileDownloadUrl);
});
}
BACKEND CODE
import wixData from ‘wix-data’;
import { mediaManager } from ‘wix-media-backend’;
export async function myGetDownloadUrl() {
return wixData.query(“sample collections”)
.find()
.then(async(results) => {
if(results.items.length > 0) {
let item = results.items[0];
const myFileDownloadUrl = await mediaManager.getDownloadUrl(item.document, 1);
return myFileDownloadUrl;
} else {
return{success:false};
}
});