Trying to download a base64 converted csv file in React

1.8k Views Asked by At
<a href={getDocLink(item.data)} download={item.name}> // item: { data: <base64URL>, name: 'Mortality' }
  Download
</a>
const getDocLink = (url) => {
  const str = url.substring(url.indexOf(";") + 1);
  return `data:text/csv;base64,${str}`;
};

When i run this code in mac, i am able to download file like Mortality.csv once i click on Download, But when i run the same in windows, i am able to download a file but, its not saving as .csv, It is saving without .csv format like Mortality

1

There are 1 best solutions below

0
On BEST ANSWER

add .csv to download

<a href={getDocLink(item.data)} download={item.name+ '.csv'}> // item: { data: <base64URL>, name: 'Mortality' }
  Download
</a>