Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Force download on click on autocomplete suggestion #401

Open
romainpoirier opened this issue Feb 21, 2023 · 3 comments
Open

Force download on click on autocomplete suggestion #401

romainpoirier opened this issue Feb 21, 2023 · 3 comments
Labels
enhancement New feature or request

Comments

@romainpoirier
Copy link

Thoroughly Describe the solution you'd like
Download a file on click on suggestion.

Please provide a few use cases for this feature

  1. The autocomplete is a search box for files
  2. The suggestions could be clicked to directly download the files suggested

Please Describe alternatives you've considered
My suggestions are download links, and this is my setup:

events: {
  input: {
    selection: (event) => {
      const selection = event.detail.selection.value;
      autoCompleteJS.input.value = selection.value;
      if (typeof selection.url != 'undefined') window.location.href = selection.url;
    }
  }
}

Even if adding this to the htaccess, the files aren't downloaded:

<FilesMatch "\.(?i:pdf)$">
  ForceType application/octet-stream
  Header set Content-Disposition attachment
</FilesMatch>

If looks like I can't force download from window.location.href, so I'm looking a way to act like the download attribute of a <a> link (which is working fine in modern browsers).

@romainpoirier romainpoirier added the enhancement New feature or request label Feb 21, 2023
@trasherdk
Copy link

Open the link in a new window, with response having correct type.

@romainpoirier
Copy link
Author

romainpoirier commented Feb 22, 2023

Sorry please can you provide an example? Can't figure out what your're suggesting.

I tried to open in a new window (this is working):
window.open(selection.url, '_blank');

But with this in htaccess, the files aren't downloaded (PDF file is still showing instead of downloading):

<FilesMatch "\.(?i:pdf)$">
  ForceType application/octet-stream
  Header set Content-Disposition attachment
</FilesMatch>

With this, I haven't the expected result as I can get using the download attribute on a <a> link.

How to force the response to download it instead of showing it?

@trasherdk
Copy link

I did the window.open(selection.url, '_blank') thingy and server-side, in PHP, letting the endpoint set application/octet-stream in the response.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants