Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Downloadable File - Gatsby

Tags:

reactjs

gatsby

For some reason when trying to download a file, it fails. I've tried few different ways, all of them failed. Than I read something about pdf/word files are "forbidden" in Gatsby ??!

The default <a href="route-to-file" download></a> doesn't seem to work, it shows failed to download. Any help is appreciated!

like image 272
ilkovs Avatar asked Jul 29 '19 17:07

ilkovs


People also ask

How does Gatsby use local images?

If you are using a local image, copy it into the project. A folder such as src/images is a good choice. Add the StaticImage component to your template.

What is Gatsby cloud?

Gatsby Cloud is a cloud platform specifically built for building, previewing, and deploying Gatsby websites. Your site is built & deployed in real-time on a global Edge network that provides millisecond load times for site visitors around the world.


1 Answers

See Importing Assets Directly Into Files and Using the Static Folder

import React from "react"
import downloadFile from '../downloads/file.pdf' 

  const IndexPage = () => (
  <>
    <a href={downloadFile} download>Download the directly imported file</a>{` `}
    <a href={`download.pdf`} download>Download the file that is already in your static folder</a>
  </>
)

export default IndexPage
like image 121
ksav Avatar answered Oct 11 '22 13:10

ksav