Reputation: 29
I am trying to download the pdf using "download" attribute in an <a>
tag:
<a className="sl_link" href={'./myfiles/abc.pdf'} target="_blank" download/>
But it is only opening in the next tab not downloading.
Upvotes: 2
Views: 6425
Reputation: 1
What I did on my react app using typescript is as shown below
<a href={require('url path')} download={'File name'} > Download </a>
Example
<a href={require('../assets/doc/resume.pdf')} download={'Resume_Pdf'} > Download </a>
Upvotes: 0
Reputation: 59
import the file like normal in React
import myResume from "../../assets/myResume.pdf";
(you choose your own path this is just an example)
after that you just have to add the reference to you href="" and thats all.
<a href={myResume} download>
Upvotes: -1
Reputation: 2932
For reactjs, download
att need value:
<a href={fileUrl} download={originalName}>your link</a>
fileUrl must be the same origin with the page
Upvotes: 3