-3
<a href="https://file-server/doc.txt" download> </a>

How can I force download file rather than open it in browser ?

I used download attribute, but it doesn't work with externals URLs

I had found a server-side solution but I don't have access to the file server

Any solutions please ?

Abadou
  • 92
  • 1
  • 2
  • 6
  • Are you creating a blob? – Ricardo Ferreira Jul 25 '19 at 15:46
  • You need to set a middle page between link and file with Content-Disposition: attachment and the file. Here a php example: https://stackoverflow.com/a/46049403/11368483 ah here a node example: https://stackoverflow.com/a/7288883/11368483 – red Jul 25 '19 at 15:48
  • Is it just a href for download or you have some kind of data( blob/ base64 etc)? – nircraft Jul 25 '19 at 16:05
  • I dont create a blob, I have just href urls. I am front end developer i use angular and i wonder if there is a client-side solution. – Abadou Jul 25 '19 at 16:14
  • If you need a pure front-end solution, you may want to use file-saver package : https://www.npmjs.com/package/file-saver – Elise Patrikainen Jul 25 '19 at 16:28

1 Answers1

-1

Put files you wanna put to download on ZIP file. After you put to download, like:

<a download href = "[ZIP file with what you wanna put to download on]"></a>
  • This doesn't answer the question as asked. The files are on an external server, if they were local and available to insert into a .zip file then it would be possible to set them to be downloaded rather than opened by the average browser. – Jason Aller Jul 25 '19 at 17:17