Creating dynamic file name for file download in api

The server side file download step in an api doesn't give the option to provide a dynamic name for the downloaded file.

I want to save the file with the name dynamically assigned with the set value
image

image
placing the set value 'file name' in curly braces doesn't work either.

Is this possible and how would I achieve this??

Thanks

i have the same problem to pull in the the FILE NAME.. but im using a button click event to do the download

<a class="btn btn-info btn-md text-white mr-1 mb-0" style="width: 140px;" dmx-on:click="download1.download('uploads/'+file_one)" dmx-bind:filename="file_title"> Download <i class="fas fa-download"></i></a>

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?

Can you please advise @Teodor

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.');
    }

If using node, this extension may help.

1 Like

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.

As i have tried

dmx-bind:filename="file_title"

but no luck

Very cool... only problem is.. im using PHP :slight_smile: and that is my "problem" :slight_smile:

Are you using a serverside or clientside download? These are two different things.
The topic here is about serverside files downloads.

100% let me open another topic then :slight_smile: and raise the question there. Thank you