I am trying to download a CSV file which resides in my project assets folder by clicking an anchor tag. But when i do this i got an error message like this ""File wasn’t available on site". Tried many solutions, but none of them work.
My snippets are below. Any help is much appreciated.
<a href="/assets/UserListSample.csv" download="UserListSample.csv">
Click here
</a>
2
Answers
You’ve got two options:
1 Import the file
Yor bundler should automaticaly bundle the file and adjust the
href
.2 Place the file in the public folder
Given the snippet:
I conclude you should put the file in
public/assets/UserListSample.csv
; bundlers put everything from thepublic
folder into the package as-is, so it should be available for download after you run the app. You need to put the right path in the code yourself.3 If above doesn’t work
It’s probably bundler’s fault. Try building the app (probably
npm run build
) and investigate the contents of the built package – see if the file is there somewhere. If it’s not then it means it’s not bundled properly. Search forUserListSample
in other files to find thatanchor
you made – see what the path is – does it actually point to the file?You can also just share more code, including
package.json
and other files related to how you run your app. The CodeSandbox is a great tool for this (even if the sandbox might have some limitations disallowing to actually download files, a Proof of Concept can still be made).Always try to place the assets in the
app_name/static/data
folder