top of page
This is an example page to illustrate a problem with the 'getDownloadUrl()' function.
A valid wix image URL is sent to the 'getDownloadUrl()' function in the backend and although it does return a download URL this only opens in a new tab and, in the case of the second button, doesn't give the image the new filename.
Buttons loaded and ready to go.
Button 1  uses getDownloadUrl() in the backend to download file with original file name 
downloadWithFilenameButton  uses getDownloadUrl() in the backend to download file and renames the file.
getFileUrlButton uses deprecated function getFileUrl() in the backend to download file.
All three buttons succeed only in opening the file on a new tab
Frontend code:

import { myGetDownloadUrlFunction, downloadWithNewFileName, getFileUrl } from "backend/downloadFile.web";

 

$w.onReady(async function () {

let fileURL = "wix:image://v1/104041_2b17502c36d946f0a90fbba08041ce3d~mv2.jpg/2.jpg#originWidth=200&originHeight=200";

 

$w('#downloadButton1').link = await myGetDownloadUrlFunction(fileURL);

 

const fileToDownLoad = await downloadWithNewFileName(fileURL, null, "myNewFile.jpg", null);

console.log(fileToDownLoad);

$w('#downloadWithFilenameButton').link = fileToDownLoad;

 

$w('#getFileUrlButton').link = await getFileUrl(fileURL);

 

$w('#loadingText').text = "Buttons loaded and ready to go.";

 

console.log('Loaded test05 page');

});

Backend code:

import { Permissions, webMethod } from 'wix-web-module';

import { mediaManager } from 'wix-media-backend';

 

export const myGetDownloadUrlFunction = webMethod(Permissions.Anyone, async (fileUrl) => {

const myFileDownloadUrl = await mediaManager.getDownloadUrl(fileUrl);

return myFileDownloadUrl;

});

 

export const downloadWithNewFileName = webMethod(Permissions.Anyone, async (fileUrl, expirationTime, downloadedFileName) => {

const myFileDownloadUrl = await mediaManager.getDownloadUrl(fileUrl, expirationTime, downloadedFileName );

return myFileDownloadUrl;

});

export const getFileUrl = webMethod(Permissions.Anyone, async (fileUrl) => {

return mediaManager.getFileUrl(fileUrl);

});

bottom of page