How do i auto-download a xlsx file i get returned from an external server?


So I got a dedicated server that I use to send values to, it will generate a spreadsheet (XLSX). And i get the return

Response from the server, i know this is correct and its the XLSX file.

back and code below

import { fetch } from 'wix-fetch';

export function sendDataToServer(eventName, date, location, teams) {
    const url = "what ever floats your";
    // const data = {
    //     eventName: eventName,
    //     date: date,
    //     location: location,
    //     teams: teams
    // };

    const data = {
        eventName: 'eventName',
        date: 'date',
        location: 'location',

    return fetch(url, {
        method: 'post',
        headers: {
            'Content-Type': 'application/json'
        body: JSON.stringify(data)
    .then(response => response.text())
    .catch(error => console.error('Error:', error));

Front end code:

import { sendDataToServer } from 'backend/CRON.jsw';

$w.onReady(function () {
    $w("#button1").onClick(async () => {
        let eventName = $w("#eventName").value;
        let date = $w("#date").value;
        let location = $w("#location").value;
        let teams = $w("#teams").value;

        try {
            let downloadURL = await sendDataToServer(eventName, date, location, teams);
            if (downloadURL) {
                $w("#downloadFrame").src = downloadURL; // This will trigger the file to be downloaded
            } else {
                console.error("No download URL found in response");
        } catch (error) {
            console.error("Error sending data:", error);

I try to create a HTML insert and prompt it to download through there. I try to have a document element and upload it into that and then promp an download, but a simple promp/ instant download to user i cant get it to work

But now I can’t get a prompted to get it downloaded on Wix… How do I get this file to download to the user, i don’t want to store the file as it’s not needed for me to keep on the server.


Perhaps by sending the user to the download URL with

I haven’t tried but it should work.

Thanks but it wont work as I’m not having a URL where this can be downloaded. The return is a auto-generated xlxs file that i cant store on the server. I mean i could but it takes more work for me do so…

But i got the solution, about 2 hours ago and it works now :slight_smile:
I create a html container, and tunnel the data into the HTML container and then there I’m able to process it into a xlsx file and auto-download.

so its working now!

1 Like