and for the life of me i cant get a "file name" to work, at least i can get the file to to download 'dmx-on:click="download1.download('uploads/'+file_one)"'
How would one add a "dynamic" file name to the above?
Here's how I do it. It took a few searches in the forums to figure this out...
I start with a query to get the file paths of the files to be downloaded. This is passed in from the client-side. I use a set value to create the path and name of the zip file...
This next part is where we always trip up. You pass in the Set Value for the "Zip File". Note the way the "Files to Add" looks. It takes a query object. I don't remember being able to just add paths to files directly here. I probably have few posts on the forums regarding this property and how to use it correctly.
And then lastly, the File Download element. You don't have to give it a File Name. That option overrides the Set Value name. I want the user to see the file name I used in the Set Value. So just reference the Set Value
On the client-side, the user can select multiple files to be downloaded at once. I call a javascript function to handle getting all the selected files and calling the server action (passing in the list of files) in a new tab, which closes automatically when the download is completed.
function DownloadSelectedPictures() {
console.log('DownloadSelectedFunction called.');
const checkedCheckboxes = document.querySelectorAll('input[name="checkbox-Item[]"]:checked'); // Get all checkboxes
const checkedValues = Array.from(checkedCheckboxes).map(cb => cb.value); // Get the values of all the checkboxes
//console.log('Checked checkboxes:', checkedCheckboxes);
//console.log('Checked values:', checkedValues);
if (checkedValues.length === 0) {
alert('Please select at least one picture to download.');
return;
}
// Here the function is defined
const downloadUrl = `/api/zone/downloadPictures/${checkedValues.join(',')}`;
//console.log('Download URL:', downloadUrl);
// Here the new window opens with the url, starting the download
window.open(downloadUrl, '_blank');
//console.log('Download started in new tab.');
}
Your expression is wrong. It's {{file_name}} that you need to enter there if you want your file name to have a dynamic name, that comes from the file_name set value step.
Hi @Teodor how do i get the "file name" to work with the "on:click="download1.download" as there is no option for a File Name .... in the Actions Editor.