How to download a file from framework ?

Hi,

I try to offer a file download from a framework app but no luck. Looks like a simple href filepath doesn’t work. DOM.download is not available…
I am stucked.

I found a notebook from Mike Lazy Download / Mike Bostock | Observable. Is it the way to go in framework ?

Any hint would be welcomed.

Have a nice day

Alain

Are you trying to download a static file that exists in your project, or something you’re creating dynamically in the browser?

For a static file, you can use <a href="./file.csv" download> to create a link.

For a dynamic file, you can copy the implementation of DOM.download into your app to use it.

Hello,

Yes a static file will be enough so far. So I tried again <a href="./file" download> but no success. My file is written by writeFileSync as ./src/data/history.json, what would be the corresponding URL to download ? I get Observable Page not found for every combinations I tried.
The second solution is well noted and I am going to try it.

I am totally amazed by your reactivity. Thank you … so so much !!

Have a good day

Alain