Question:
How to download automatically a csv file into users navigator?
Product:
Wix Editor
What are you trying to achieve:
The idea is that the user click on a bottom that allows to download de csv file of a dataset! I already have my back end function on my own server that manages the data of dataset and retrieves a HTTPS response
I’m only been able to make it “downloadble” the document on users console
What have you already tried:
function downloadUsers() {
const token = local.getItem('token');
fetch("https://example.com/example", {
method: 'GET',
headers: {
'Authorization': `Bearer ${token}`
}
})
.then((httpResponse) => {
if (httpResponse.ok) {
return httpResponse.blob();Blob
} else {
return Promise.reject("Hubo un problema con la descarga.");
}
})
.then(blob => {
const reader = new FileReader();
reader.readAsDataURL(blob);
reader.onloadend = () => {
const base64Data = reader.result; // data:text/csv;base64,...
console.log(base64Data)
};
})
.catch(error => {
console.error('Error al descargar el archivo:', error);
});
}
Additional information:
Thanks!