Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

button to download a pdf file using Next js

I'm trying to create button that if I click it should download the file. I work on Next js

    <a href={cv} download="name cv.pdf"> Download CV </a>

I did this code in react and run correctly but when I try it in next js I get "Failed - No file". I'd like to figure out what's causing this issue

like image 681
S H N Avatar asked Oct 16 '25 02:10

S H N


1 Answers

I assume you are trying to serve a static pdf file in your nextjs project.

Please make sure the file is in public/ folder. For eg., let's assume the file is placed in public/cv.pdf.

Then, the anchor tag should be

<a href="/cv.pdf" download="cv">Download CV</a>

If you're trying to serve from a cdn, please ensure the cdn link is valid.

<a href="https://mycdn.com/assets/cv.pdf" download="cv">Download CV</a>
like image 181
Bug Reporter Avatar answered Oct 17 '25 15:10

Bug Reporter