'JS download doesn't download entire file

I am trying to download a csv file with 3607 lines (1.0 Mb):

const hiddenElement = document.createElement('a');
const fileContent = `data:text/csv;charset=ansi,${res.data}`;

hiddenElement.href = fileContent;
hiddenElement.target = '_blank';
hiddenElement.download = 'file.csv';
hiddenElement.click();

The content at res.data is complete (as well as fileContent), but when i download the csv, the file only has 149 lines (4.4 Kb) instead of the original size.

Can someone help me please?



Solution 1:[1]

The problem was that URLs cant have more than 2,048 characters

Solution 2:[2]

I faced the same problem and the same CSV download used to work earlier and download complete file.

had to change to the following:

const blob = new Blob([csvData], { type: 'text/csv' })
const url = window.URL.createObjectURL(blob);
const link = document.createElement('a')
link.setAttribute('href', url)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Jorrmungandr
Solution 2