SUMIT KUMAR
SUMIT KUMAR

Reputation: 29

Download attribute is not working inside the <a></a> link in React js

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

Answers (4)

Kanu mike
Kanu mike

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

ispasDani
ispasDani

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

vicky patel
vicky patel

Reputation: 705

<a href="url" download="xyz.pdf">Download File</a>

Upvotes: 0

Khoa
Khoa

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

Related Questions