Download a file from a server using HTML-page (Java, HTML) - html

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.

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>

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

Related

Image not showing in browser on local server (Live server extension) but shows when opened from explorer

I am having problem in HTML . My Image is not showing in browser (Firefox) when html file is opened through live server extension (VS code).It throws a Security error that html file can't link to image. I want to use image as background.
My html file is folder in D: drive.
Path = D:/myhtml/index.html
And my image is in F: drive
Path = F:/mountain.png
my img tag is
<img src="f:/mountain.png" alt="mountain"/>
But when I open html file directly from file explorer image shows up.
Please help to solve this problem.
Live server in made to behave like a real web server (one that is online on the web, called via http(s), and does not have access to your local hard drive file system "the Windows way" with F: etc.
Going to F:// is only possible on your own machine and will never work online. Browsers have built in a way for you to browse your local files like that. Web servers don't have this feature.
Use HTML file paths, meant for the web server:
Absolute path: https://example.com/images/mountain.png (path to an online destination which could be another domain than yours)
Relative path: images/mountain.png (relative to where your html file is located on your own web server)
Relative path to a folder outside of where your html is located: ../../etc/images/mountain.png

Downloading file from ubuntu server through html

I have my domain pointing at a ubuntu server hosted by amazon ws, and I have my index.html file that gets loaded when someone makes a request to my domain, in the same folder of that index.html file I have another file, and I would like to make it possible to download it from my website. How can I achieve that? I tried with an iframe tag, and giving it src="./myfile.jpg" but the server tries to look for it at www.mydomain.com/myfile.jpg and it can't find it there. Can anyone give me any suggestions?
Btw my files are inside /var/www/html folder, which from what I understood is the default folder for public files on ubuntu.

how to run html on python openshift server

I have an OpenShift server running python. However when I call php via SSL the php interpreter starts running. It suggests that there might be a way to run php as well. However, HTML if fair enough for me. Now, I do not know how to be able to reach html files on my server as when I am trying I always get 404 not found. I've read about a solution of placing a .htaccess file:
AddType application/x-httpd-php .html
I am not exactly sure where to place this file but placing in the folder of the .html file still not helps.
Could you please help me how I can make .html files reachable at an OpenShift server running Python? How about php?
Put the .html file in your app-root/repo/wsgi/static folder (or in that folder in your git repository). if you want it to be displayed like app-domain.rhcloud.com/file.html, you will have to use a .htaccess file in your wsgi folder that rewrites file.html to static/file.html

Cannot find URL error while it is definitely there

I have small CGI script running on a server[Linux OS]. following is a part of script output..
<tr><td valign="center">Lol</td><td valign="center">10112</td><td>abc.pdf</td></tr>
But when I click on this abc.pdf hyperlink, browser displays error message:URL /home/pathtopdf/abc.pdf was not found on the server. while the pdf and path is definitely there and all files and folders in the path[including pdf] has full permission.
My server location is # /srv/www and script in /srv/www/cgi-bin, but when I put the link to pdf as follows
<tr><td valign="center">Lol</td><td valign="center">10112</td><td>abc.pdf</td></tr>
The error message was The requested URL '/srv/www/for_html/abc.pdf' resolves to a file which is marked executable but is not a CGI file; retrieving it is forbidden. Again permission is there for files.
What could be the problemo?
Your problem is that you try to request a file outside of the webroot. So by clicking that, the browser is really requesting
http://example.com/home/pathtopdf/abc.pdf
not
/home/pathtopdf/abc.pdf
You can edit your apache config file and add a virtual host to that directory under a subdomain (say downloads)
After your edit, I am assuming you are using the file:// protocol, directly on the server. I would say just to remove the executable bit from your .pdf's file permissions. Run from a shell:
chmod -x /srv/www/for_html/abc.pdf

link file extension correction

I was just crafting some html for a webpage on a local server on my mac. I added a link to a stylesheet stored on my local server, but forgot to add the ".css" file extension in the href attribute. I didn't realize my mistake until I uploaded my files to an externally hosted server--because somehow the stylesheet could be found without the extension on my local server, whereas when I tried to load the page from the external server the extension was not assumed and my styles didn't load.
What entity figured out my error and corrected it locally, and why wasn't my error corrected when the page was hosted externally?
It could be that your local web server is serving the file up as text/css and the external one is not. What happens if you use TYPE="text/css" inside your LINK tag to the CSS file? That should force it to interpret the linked file as text/css.