How to enable download on my site hosted by GitHub.io? - html

On my site hosted by GitHub.io, I have a download button like the following:
<a href="link to the file" download>Download</a>
However, when I click on it, it redirects me to the page where the file is located. How do I enable download rather than redirecting?

The download attribute only works for same-origin URLs. So if the href is not the same origin as the site, it won't work.
In other words, you can only download files that belongs to that website.
Here's a more detailed explanation of the same.

Related

Can't download file using HTML5 download attribute

I'm trying to create a download link the way it always worked for me. But now it keeps redirecting me to Google Docs – I've never experienced that before, this should be a straight-forward task to do, so it quite shocked me.
I use the HTML5 download attribute:
<a href="../files/uploads/myfile.docx" download>myfile.docx</a>
But I always end up redirected to Google Docs. I also opened the Chrome dev console and noticed that after I click on the link, it changes the href to Google Docs. I have no clue why.
The path should be alright, I can't figure out the problem. What shall I do?
The download attribute only works for same-originl URLs. So if the href is not the same origin as the site, it won't work. In other words, you can only download files that belongs to that website. This attribute follows the same rules outline in the same-origin policy

How to Make a Direct download link of an embedded Video

I have a Souce URL of a .MP4 video
here is the URL: http://naruto.manga47.net/Naruto_Dub/040.MP4
to download this video we have to open the link and wait for it to load and then we will be able to
download it by right-clicking on it and saving it as a video.
the Question is That ** I want to get a Direct download link of this video. After pasting the Direct link in a browser it will start downloading the video without any second click**
please tell me if this is even possible.
-Thank You
You can use tag to do this. I suspect somewhere in your code you have an link to this address. Just put a download tag after it like this:
<a href="/download/Naruto_Dub/040.MP4" download>
or like this:
<a href="/download/Naruto_Dub/040.MP4" download="Naruto Video">
and then it will tell the browser to download the file in that link. For more in-depth info read here: https://www.w3schools.com/tags/att_a_download.asp
EDIT: Chrome 65+ and Firefox only support same-origin download links, due to security reasons. You would need to download the file yourself, and put it somewhere on your website and then link it to your own website.
So basically you have a direct link of a file on internet, That is this : http://naruto.manga47.net/Naruto_Dub/040.MP4
the easiest thing you can do is just add ?dl=1 at last in the link in order to download it.
Now the link will be :
http://naruto.manga47.net/Naruto_Dub/040.MP4?dl=1

How to add download link to html, where href is a .mp4 that is hosted online?

I want to allow a user to download a .mp4 file that is hosted on Cloudinary. I currently have this:
<a
target="__blank"
href='https://res.cloudinary.com/dental-
intelligence/video/upload/v1576364994/ippevbecmsljhzkfklyi.mp4'
download
>
Download
</a>
but all it does is open the url and begin playing the video. Is there a way to download it directly to the user's computer once they press download?
You'll need to remove the target attribute and use the attachment flag in Cloudinary (fl_attachment).
<a href='https://res.cloudinary.com/dental-intelligence/video/upload/fl_attachment/ippevbecmsljhzkfklyi.mp4'>Download</a>

HTML 5 a Tag not downloading file but open a new page

I am trying to make a downloadable file on my web page with this
<a href="http://ir-devtestsvr/4ms/media/e54d5f61-7375-405a-a6af-bb37f2447991.PNG" download>View file here</a>
but when I click the element, it just opens a page that views the file but not download the link. How can I do that when I clicked the element it will download the file.
The download attribute only works for same-origin URLs. Is the file you want to make downloadable hosted on the same protocol, port, and host as the page? Even something as small as the page or file being served as http and the opposite being served as https will break it. See more at: https://developer.mozilla.org/en-US/docs/Web/Security/Same-origin_policy

How can I make a url a download link in html?

A client wants a url to be a download link.
Use case is like so:
user gets linked to example.com/download once there, it downloads a pdf file.
Can I do this without php ?
HTML5 introduced the download attribute.
Supporting user-agents will offer to download the file foo.png when clicking this link:
<a href="foo.png" download>Save the image</a>
You can also specify a different default file name that should be used:
<a href="foo.png" download="image.png>Save the image</a>
Read more at http://www.w3.org/TR/html5/links.html#downloading-resources.
Note that this only works for links. When users enter the URL directly into their browsers, this will have no effect, of course. If you want that, you need to send specific HTTP headers. See for example the question: How to force download of a file?. You don’t necessarily need a programming language like PHP for that. You can do it with, for example, .htaccess, too: Force File(image) Download with .htaccess
How a file is displayed is browser specific. Some may force you to download while some directly render it on the browser.
If you want to force the browser to download the file then you can set in Header the
Content-Type : application/octet-stream
You only need a link (anchor tag). The way the link behaves on click will depend on what browser you are and what settings you have in that particular browser. Some browsers will prompt you to open or save the file, other browsers will open the PDF file on a new tab or window.
Download PDF
You'll also need to make sure that the path to the PDF file is correct on the href property of your anchor tag.
Use this (HTML) not PHP:
Download pdf
Use the full url including the pdf file like.
Download