简体   繁体   中英

Trying to download a base64 converted csv file in React

<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

add .csv to download

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM