0

I want do download a CSV with the click of a link.

My endpoint is a 'POST' and since I'm unable to do it directly with the <a> tag, I wrapped it in a form.

This is my code:

<form method="post" action="/api/summary?type=download&limit=all">
   <a onclick="this.parentNode.submit()" class="download-sumary" download>Download</a>
</form>

The endpoint returns the response correctly, but the download is not working.

Can I use the download attribute on an anchor inside a form? If not, how can I achieve this?

PS: The CSV is being created in the back-end

MCM
  • 141
  • 2
  • 12
  • [POST](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/POST) is an `HTTP method`, not an `endpoint`. The [download](https://www.w3schools.com/tags/att_a_download.asp) attribute only works if the anchor also has an `href` attribute. [See here](https://stackoverflow.com/questions/19327749/javascript-blob-filename-without-link) for different ways to convert data to a downloadable [BLOB](https://developer.mozilla.org/en-US/docs/Web/API/Blob). – PoorlyWrittenCode Jun 22 '21 at 01:42

0 Answers0