0

I would like to download a file throw the link from my html-page.

I have this file in a folder on the server. I have shared this folder for all. The path to my file, for example is:

//bogn/folder/spi.jar 

If I enter the path

file://bogn/folder/spi.jar 

directly to the browser URL - then downloading is going successfully.

As I need to download the file from the HTML-page I use link:

<a href="file://bogn/folder/spi.jar" download> Download JAR </a>

The browser asks the question whether to save the file and then ignore saving. I can see the error: Network error.

How I can fix this? Thank you.

Kirill Ch
  • 5,496
  • 4
  • 44
  • 65

2 Answers2

0

The path to the file needs to be publicly accessible. If, for example, your html file in in the root web directory, and your jar file is inside "folder" in the same directory, then this will work:

<a href="folder/spi.jar" download> Download JAR </a>
HomerPlata
  • 1,687
  • 5
  • 22
  • 39
  • Absolutly. However the file located on the server, how I mentioned above. – Kirill Ch Mar 21 '17 at 09:16
  • Then like Justinas mentioned, you should use the full http(s) path. If you're looking to make a file in a non-public location downloadable then you'll have to use a bit of PHP, or even a REST API for returning files from protected locations. – HomerPlata Mar 21 '17 at 09:24
  • I have full control over the server. So I have shared the access to the folder for all users, make it publicly accessible. – Kirill Ch Mar 21 '17 at 10:58
  • Publicly accessible via http though? – HomerPlata Mar 21 '17 at 10:59
  • Detailed situation is this. I have an application with server-side on Java and web-client with Angular. I use Maven to create starting jar-file. Now I use our corcorate server and create there a folder for my application. When I start the app on the server then users can connect to it through the browser. Then my server creates some file, that users should have the possibility to download on their local machines. – Kirill Ch Mar 21 '17 at 11:40
  • So I have given a public access to the folder where my file is located and the path to it is: //bogn/folder/spi.jar – Kirill Ch Mar 21 '17 at 11:53
0

The similar issue: how to create an anchor to a file in remote server in html

So it seems in Chrome and Firefox it is not allowed to download the files such way from remote server.

I have found the solution: I start using Servlets in Java and successfully download the files from remote server to browser.

This link was helpful for me: http://www.journaldev.com/1964/servlet-upload-file-download-example

Community
  • 1
  • 1
Kirill Ch
  • 5,496
  • 4
  • 44
  • 65