skip to Main Content

I currently store my woocommerce product files on S3 in the following format:

/bucket/{product_id}.zip

When a customer clicks the download link in their customer dashboard the element is as follows:

<a href="https://url/1234.zip">Download Product Name</a>

This downloads the file into their downloads folder as 1234.zip

I would like to be able to pass some values to the request so that the filename can be downloaded as {param1}-{param2}.zip

2

Answers


  1. Like this:

    <a href="https://url/1234.zip" download=`${param1}-${param2}.zip`>Download Product Name</a>
    

    Refer: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#attr-download

    Note:

    download only works for same-origin URLs, or the blob: and data:
    schemes. How browsers treat downloads varies by browser, user
    settings, and other factors. The user may be prompted before a
    download starts, or the file may be saved automatically, or it may
    open automatically, either in an external application or in the
    browser itself. If the Content-Disposition header has different
    information from the download attribute, resulting behavior may
    differ: If the header specifies a filename, it takes priority over a
    filename specified in the download attribute. If the header specifies
    a disposition of inline, Chrome and Firefox prioritize the attribute
    and treat it as a download. Old Firefox versions (before 82)
    prioritize the header and will display the content inline.

    Login or Signup to reply.
  2. When they click a button to download the file, you can add the HTML5 attribute "download" where you can set the default filename.

    https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#attr-download

    <a href="https://url/1234.zip&quot; download={${param1}-${param2}.zip}>Download Product Name

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search