import axios from 'axios' import fileDownload from 'js-file-download' export default function App() { const handleClick = (url, filename) => { axios.get(url, { responseType: 'blob', }) .then((res) => { fileDownload(res.data, filename) }) } return ( <div className="App"> <button onClick={() => {() => handleClick('https://avatars.githubusercontent.com/u/9919?s=280&v=4', 'sample')}}> Download the File</button> </div> ); }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter