Download img src when connected image is clicked.

Hi I am not super great with code, but I need a .png file downloaded when a connected image on a dynamic page is clicked.

All I have currently is:

import wixLocation from ‘wix-location’ ;

export function image31_click ( event ) {
let imageSource = $w ( ‘#image31’ ). src ;
wixLocation . to ( https://static.wixstatic.com/media/ ${ imageSource } ?dn=$w{'#t_fileName'} );
}

Which obviously does nothing. Preferably the image downloads as the specified fileName.
The image is on a single Dynamic Item page

thanks!

Change it like that:

Backend Function to get URL:

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

export async function myGetDownloadUrlFunction(fileUrl) {
    const myFileDownloadUrl = await mediaManager.getDownloadUrl(fileUrl);
    return myFileDownloadUrl;
}

Frontend:

import { myGetDownloadUrlFunction } from 'backend/aModule.jsw';

export async function image31_click(event) {
    let url = $w('#image').src;
    const downloadUrl = await myGetDownloadUrlFunction(url)
    wixLocation.to(downloadUrl)
}

This should work for you.

API : getDownloadUrl - Velo API Reference - Wix.com

Ok I see, still not quite there though, as it doesn’t recognize #image, as it doesnt seem to be part of the dynamic dataset. How do I reference #image within the dynamic dataset?

do I have to reference $w ( ‘#dynamicDataset’ ) somewhere to get the code to recognize #image?

If you want, you can give access to your website so I can handle it. (aydontloss@gmail.com)

sorry, I am building this for a friend and I can’t reach him for permission for that. I’d love to give you access but I can’t contact him for a while.

The image to click is in the top right corner. Here is is with the page code.
It’s image is linked to the Dynamic Dataset under #imageToken

Are you trying to get the image url from database? Can you explain exactly what you want to do?

And you need to change imageToken to your image ID.

I tried #image #image31 with the same results. but Ok, I will keep it at #image31

The crab picture (image31) needs to be downloaded when clicked. But its not just the crab picture, but all other insects and creatures that will be in place of image31 for the Dataset. The image varies per the dataset, so clicking the image needs to download the original .png of whatever image happens to be in that place.

Other images on the page (image32 and image33) will be the same. So each page will have multiple images in different places that download when you click on them. All pulled from a dynamicDataset named “Monsters Item”